When I send Json data, it arrives as null when I verify my method in the controller
Simplified HTML:
<div class="child">
@Html.LabelFor(m => m.Project, new { @class = "", style = "color:#040404" })
@Html.DropDownListFor(Model => Model.ProjectID, Model.Project, "Select")
@Html.ValidationMessageFor(Model => Model.Project, null, new { @class = "label label-danger", id = "Project" })
</div>
<div class="child">
<input type="button" id="add" value="Add" class="myButton">
</div>
JavaScript snippet:
$('#add').click(function () {
debugger;
var data= {
Project: $("#ProjectID option:selected").text()
};
$.ajax({
url: "../HandleData",
type: "POST",
dataType: "json",
data: JSON.stringify(data),
success: function (mydata) {
$("#UpdateDiv").html(mydata);
history.pushState('', 'New URL: ' + href, href); // This Code lets you to change url howyouwant
}
});
}
Controller method:
public JsonResult HandleData(string Project)
{
........
...
return Json(Project);
}
Error message in console:
https://i.sstatic.net/4V2lk.png
I'm unsure of what could be causing this issue. Any help would be greatly appreciated.
Thanks!