I work on asp.net mvc i face issue i can't auto update reason using java script ajax
auto update meaning when user start writing on reason it will save on database table
update i need will done without using update button it will auto save using java script ajax or jquery
my html as below
@model HR.WorkforceRequisition.Models.ResignationRequester
<table style="border: 1px solid black;width:100%;">
<tr>
<td style="width: 50%; font-weight: bold; padding-top: 10px;">
<div class="form-group hover">
@Html.LabelFor(model => model.RequestNo, htmlAttributes: new { @class = "control-label col-md-5" })
<div class="col-md-7" id="RequestNo">
@Model.RequestNo
</div>
</div>
</td>
<td>
<div class="col-md-7" id="Reason">
@Html.TextAreaFor(model => model.Reason, new { id = "txtreason", @class = "form-control" })
</div>
</td>
</tr>
</table>
action will update on database will be as below
public JsonResult Edit(ResignationRequester req)
{
dynamic responseData = new ExpandoObject();
responseData.success = false;
responseData.message = "";
string query;
ResignationRequester workforceRequest = ResignationupdateReason((int)req.RequestNo,req.Reason);
return Json(responseData);
}
and javascript function will make update will be
java script function
function changereasonbasedonrequestno() {
console.log("fire event")
var ResignationRequester = new Object();
ResignationRequester.RequestNo = document.getElementById("RequestNo").innerHTML.trim();
ResignationRequester.NoticePeriod = document.getElementById("Reason").innerHTML.trim();
}