Getting Null Value of ViewModel obj in Post Action Parameter when using $.Ajax Post
View
@using (Ajax.BeginForm("", "", Model, new AjaxOptions() { HttpMethod = "POST" }, new { enctype = "multipart/form-data", id="AreaForm" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Areabalmodel</legend>
<div class="editor-label">
@Html.LabelFor(model => model.project.project_ID)
</div>
<div class="editor-label">
@Html.DisplayFor(model => model.project.project_ID)
@Html.HiddenFor(model => model.project.project_ID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.areabal.AreaDesc)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.areabal.AreaDesc)
@Html.ValidationMessageFor(model => model.areabal.AreaDesc)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.areabal.Location)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.files, new { Name = "files", type = "file", id = "files", onchange = "PreviewImage();" })
</div>
<p>
@*<input type="submit" value="Updated" />*@
<input type="button" id="UpdateArea" value="Update" />
</p>
</fieldset>
}
<script type="text/javascript">
$(document).ready(function () {
$("#UpdateArea").click(function () {
UpdateAreaFunction();
});
function UpdateAreaFunction() {
if ($("#AreaDesc").val() == '') {
alert('IF');
//$("#CostFieldName_span").html("Name is required");
}
else {
var dataToSend = {
areabal: {
Area_ID: 1,
Project_ID: 1,
AreaDesc : "dsdsds"
}
};
var formdata1 = $('#AreaForm').serialize();
//alert(formdata1);
console.log(formdata1);
$.ajax({
url: '@Url.Action("UpdateArea_POST", "Builder")',
type: 'POST',
dataType: 'json',
//data: $.toDictionary(dataToSend),
data: JSON.stringify(dataToSend),
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
success: function (result) {
alert(result);
}
});
}
}
});
</script>
Controller's ActionMethod
[HttpPost]
public string UpdateArea_POST(Createviewmodel Crv)
{
//Getting Null Values of all crv
return "done";
}
could help me to see the error ?