Click here to Skip to main content
15,850,360 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to get the model list from the ajax post call to post handler in 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 core razor page but not 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) {
        var ProjectData = []; 
 for (max = 0; max < 200; max += 1) {
                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 };
            type: "POST",
            url: "/EprEmployee/AddorEditEprEmployee?handler=ProjectSubmit",
            beforeSend: function (xhr) {
            data: JSON.stringify(projectDataList),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                if (response == "Sucess") {
                else {
            failure: function (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
Andre Oosthuizen 16-Feb-22 4:27am    
From what I could gather, you are calling handler "ProjectSubmit" which I think should be "ProjectData" as that contains the info you require to display.
chatarji 16-Feb-22 6:26am    
FromForm] - Gets values from posted form fields.

[FromBody] - Gets values from the request body.

I used [FromBody] instead of [FromForm] then it works for me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900