Dear Friends I am new MVC world & working in a project. I want to fill some html.editfor fields on a button click. My tried the given below codes:
Controller action:
VIEW:
On the above codes Auto complete part working pefectly, Button click not working. So, friends please help me in this regard.
Controller action:
[HttpPost]
public JsonResult GetRecordById(string id)
{
var record = dc.TABLE1.FirstOrDefault(x => x.PART_NO == id);
var result = new
{
Name = record.PARTI,
Type = record.TYPE
};
return Json(result, JsonRequestBehavior.AllowGet);
}
VIEW:
<script type="text/javascript">
$(function () {
$("#txtParti").autocomplete({
source: '@Url.Action("GetParti")'
});
});
$(function () {
$("#txtPtno").autocomplete({
source: '@Url.Action("GetPtno")'
});
});
$('#BTNFET').onclick(function (fetrec) {
var recordId = this.value;
$.post('@Url.Action("GetRecordById")',
{
"id": recordId
},
function (data) {
$("#txtParti").val(data.Name);
$("#Type").val(data.Type);
});
});
</script>
<inputtype="button"id="BTNFET"onclick="fetrec();"/>
@Html.EditorFor(model => model.PARTI, new { htmlAttributes = new { @class = "form-control", @id = "txtParti", @placeholder = "PART NAME" } })
@Html.EditorFor(model => model.PART_NO, new { htmlAttributes = new { @class = "form-control", @id = "txtPtno", @placeholder = "PART NO" } })
@Html.EditorFor(model => model.TYPE, new { htmlAttributes = new { @class = "form-control", @id = "Type", @placeholder = "ITEM TYPE" } })
On the above codes Auto complete part working pefectly, Button click not working. So, friends please help me in this regard.