User-1355965324 posted
I am calling the function filldata() while doing the changes in empcode column.
script in cshtlm
<div class="form-group">
@Html.LabelFor(model => model.empCode, "Employee", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.empCode, new {htmlAttributes = new { required = "required", @class = "form-control" , @onchange = "FillData()" } })
@Html.ValidationMessageFor(model => model.empCode, "", new { @class = "text-danger" })
</div>
</div>
@section Scripts {
<script>
function FillData() {
debugger
var Id = $('#empCode').val();
$.ajax({
url: '/Employee/EmpolyeeEmailByCode',
type: "GET",
dataType: "JSON",
data: { empcode: empCode},
success: function (data) {
$("#username").val(""); // clear
$("#username").val(data);
},
error: function (e) {
$("#username").val(""); // clear
}
});
}
</script>
}
In Controller
public JsonResult EmpolyeeEmailByCode(string EMPREF)
{
if (EMPREF == null)
{
return Json(null);
}
tblEmployee tblEmployee = db.tblEmployees.Find(EMPREF);
if (tblEmployee == null)
{
return Json(null);
}
return Json(tblEmployee.email, JsonRequestBehavior.AllowGet);
}
But EmpolyeeEmailByCode function is not calling. Any help would be very appreciated . I want to get the employee email for the given empcode.