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 Automatically based on Request No
update i need will done without using update button it will auto save using java script ajax
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 name Edit
will update on database on ResignationController
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);
}
java script function will execute when auto update will be
<script type="text/javascript">
function changereasonbasedonrequestno() {
console.log("fire event")
var ResignationRequester = new Object();
ResignationRequester.RequestNo = document.getElementById("RequestNo").innerHTML.trim();
ResignationRequester.NoticePeriod = document.getElementById("Reason").innerHTML.trim();
}
</script
model used on asp.net mvc
will be
public class ResignationRequester
{
[Display(Name = "Request No")]
public int RequestNo { get; set; }
[Display(Name = "Reason")]
public string Reason { get; set; }
}