I need to do that without using form and I will depend on java script or jQuery
I recommend that you use the form tag so that the CSRF token in the hidden field can be sent to the server together with the data of ResignationRequester class. You will be able to do so using the jQuery.
See the following sample of view including the jQuery ajax:
@model Mvc5App2.Controllers.ResignationRequester
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>ResignationRequester</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.RequestNo, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.RequestNo, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.RequestNo, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.LastWorkingDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.LastWorkingDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.LastWorkingDate, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="button" value="Save" id="ajaxUpdate" class="btn btn-default" />
</div>
</div>
</div>
}
<div id="result"></div>
@section Scripts {
<script type="text/javascript">
//<![CDATA[
$(function () {
$('#ajaxUpdate').on('click', function (e) {
// use FormData object
var fd = new FormData(document.querySelector("form"));
$.ajax({
url: '/Resignation/Edit',
method: 'post',
data: fd,
processData: false,
contentType: false
}).done(function (response) {
$("#result").empty;
$("#result").text(response);
}).fail(function (jqXHR, textStatus, errorThrown) {
$("#result").empty;
$("#result").text('textStatus: ' + textStatus +
', errorThrown: ' + errorThrown);
});
});
});
//]]>
</script>
}