Я использую ASP.NET Core 8. Как перенести модель контроллеру через AJAX?public class StudentModel
{
public int? id { get; set; }
public string? Stu_Name { get; set; }
public string? Stu_Address { get; set; }
public string? Sty_Gender { get; set; }
public int? Stu_Age { get; set; }
public string? Stu_Class { get; set; }
}
< /code>
$.ajax({
type: "POST",
url: "/Student/Create",
//data: '{saveStudentdata:' + GetData + '}',
data: JSON.stringify({ saveStudentdata: GetData }),
contentType: "application/json; charset=UTF-8",
dataType: "json",
success: function (responce) {
if (responce.saveStatus == "Success") {
alert("Data Successfully Save...");
}
else { alert("Data not Save.."); }
},
error: function (error) {
alert(error);
}
});
< /code>
Controller:
[HttpPost]
public JsonResult Create(StudentModel SaveStudentdata)
{
string Status = string.Empty;
try
{
Status = Studata.Createdata(SaveStudentdata);
return Json(new { saveStatus = Status });
}
catch (Exception ex)
{
return Json(new { saveStatus = Status, errorMassage = ex.Message });
}
}
< /code>
Update: I updated my ajax code but still controller is getting called. Data is not getting transferred.
Подробнее здесь: https://stackoverflow.com/questions/795 ... controller