I'm trying to get the model list from the ajax post call to post handler in asp.net core razor pages, I implemented the model and model list first. Later in ajax call I created the model array list and push the information into array list and call the post handler method in the ajax call in asp.net core razor page but not asp.net MVC core.
here is my code I tried
public partial class projectList
{
public List<ProjectModel> projectModelList { set; get; }
}
public partial class ProjectModel
{
public int? User_ID { set; get; }
public int Projects_ID { set; get; }
public int? EPR_Summary_ID { set; get; }
public string Self_Comments { set; get; }
public int? Self_Rating { set; get; }
public string Appraiser_Comments { set; get; }
public int? Appraiser_Rating { set; get; }
public string Manager_Comments { set; get; }
public int? Manager_Rating { set; get; }
public string supervisor_comment { set; get; }
public int? supervisor_Rating { set; get; }
public int? ID_Project { set; get; }
}
$("#btnProjectSave").click(function (e) {
e.preventDefault();
var ProjectData = [];
for (max = 0; max < 200; max += 1) {
ProjectData.push({
User_ID: 1212,
Projects_ID: 0,
ID_Project: 0,
EPR_Summary_ID: 0,
Self_Comments: "",
Self_Rating: 0,
supervisor_comment: "",
supervisor_Rating: 0,
Appraiser_Comments: "",
Appraiser_Rating: 0,
Manager_Comments: "",
Manager_Rating: 0,
})
}
var projectDataList = { "projectModelList":ProjectData };
$.ajax({
type: "POST",
url: "/EprEmployee/AddorEditEprEmployee?handler=ProjectSubmit",
beforeSend: function (xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
data: JSON.stringify(projectDataList),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
console.log(response)
if (response == "Sucess") {
}
else {
}
},
failure: function (response) {
alert(response);
}
}); })
public ActionResult OnPostProjectSubmit([FromForm] projectList projectDataList)
{
return new JsonResult("Sucess");
}
What I have tried:
I tried above code but still the data is not getting and showing as null