问题描述:

When a HttpGet is performed in ASP.NET MVC, I fill a textbox with some JSON-values which the jQuery Tokeninput can use.

[HttpGet]

public ActionResult Edit(Guid id, bool? success)

{

Section section = _sectionRepository.LoadById(id);

var viewModel = new EditViewModel()

{

// uses the JavaScriptSerializer

ParentString = GetParentString(section.Parent),

[...]

};

return View("Edit", viewModel);

}

This work as expected.

If I ,however, do a HttpPost and my model is not valid then the ParentString value isn't a JSON format anymore.

[HttpPost]

[ValidateInput(false)]

public ActionResult Edit(Guid id, EditViewModel model)

{

if (!ModelState.IsValid)

{

model.Success = false;

var parentString = model.ParentString; // no JSON anymore

return View("Edit", model);

}

}

So {"id":"e2eee66e-b0b1-4f9f-ab77-a1432da40c7d","name":"MyValue"} becomes e2eee66e-b0b1-4f9f-ab77-a1432da40c7d|MyValue,.

After a HttpPost, the jQuery Tokeninput doesn't work anymore because it expected a JSON-value.

What could cause this issue?

相关阅读:
Top