swsh hussain

swsh hussain

  • NA
  • 11
  • 11.7k

executing controller controller action method

Nov 14 2015 3:22 AM
i want to execute a controller action method soon after entering the data in a textbox glgroupcode
the action method takes  glgroupcode textbox value as a parameter  and result should get populated in  another textbox .
 the below is my jquery code and action method
 
<script type="text/javascript">
$('#GLGroupCode').on('keypress ', function (event) {
alert("s");
$.ajax({ url: "/GLMaster/TextChanged", type: "GET", data: { text: $('#GLGroupCode').val() }, dataType: 'json', success: function (result) {
$('#txtSearch1').val(result);
}
});
});
</script>
<div class="editor-field">
@Html.TextBoxFor(model => model.GLGroupCode)
@Html.ValidationMessageFor(model => model.GLGroupCode )
</div>
<div class="editor-label">
@Html.LabelFor(model => model.GLGroupName)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.GLGroupName, new { id = "txtSearch1" })
@Html.ValidationMessageFor(model => model.GLGroupName)
 
 
 
public JsonResult TextChanged(string GLGroupCode)
{
var subGroups = from p in db.tblGLGroups where p.GroupCode == GLGroupCode select p.GroupName;
return Json(subGroups, JsonRequestBehavior.AllowGet);
}
 
 

Answers (2)