当我调用 AJAX Get/Post 时,我可以将ViewModel
我的表单发送到我的 Controller 方法。有没有办法在这个请求之后用新的值重新填充表单ViewModel
?我的方法的正确返回是什么:带有 ViewModel 或 View 的 Json?像这样:
$.ajax({
dataType: "JSON",
data: $('#form').serialize(),
type: "GET",
url: "SomeController/doSomething",
success: function(myViewModel) {
// How to repopulate my form with the new values?
}
});
public class SomeController {
[HttpGet]
public ActionResult DoSomething(MyViewModel model) {
model.SomeProperty = "This property needs to be changed into the View.";
// The right way is returning a Json with the ViewModel...
return Json(model, JsonRequestBehavior.AllowGet);
// or return some View?
return View(model);
}
}