'MVC ModelState became null
[HttpPost]
[ValidateAntiForgeryToken]
public JsonResult EditPost(Expense model)
{
SetLists();
model.TravelLines = (List<ExpenseTravel>)Session["ExpenseTravelLines"];
model.ExpenseLines = (List<ExpenseLine>)Session["ExpenseLines"];
if (ModelState.IsValid)
{
...
return Json(new { success = true, message = GlobalViewRes.UpdatedSuccessfully }, JsonRequestBehavior.AllowGet);
}
return Json(new { success = false, message = GetErrorMessage(ModelState) }, JsonRequestBehavior.AllowGet);
}
This my js
$(".send-form.Travel").click(function (e) {
e.preventDefault();
var obj = $("#formEdit").serializeToJSON();
obj.ExpenseLines = data.ExpenseLines;
var id= obj.Entry_No;
$.ajax({
url: '/Expense/EditPost',
type: 'post',
data: obj,...
I enter edit to correct the data I created. The part I made changes to the model is empty. I have defined a Session. It comes to the session, but does not enter the modelstate, the expenseline is empty.How can I fix it ? Sorry for my English :)
Solution 1:[1]
try this
var obj = $("#formEdit").serialize(); //or serializeToArray()
and remove [ValidateAntiForgeryToken] while you are testing
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Serge |
