从 Ajax MVC Action 调用返回 int 的最简单方法是什么?
我正在尝试:
public ContentResult Create(MyModel model)
{
return Content("1");
}
using (Ajax.BeginForm("Create",
new AjaxOptions {
OnComplete = "function(data) { alert(data); }"
}))
我得到警报[object Object]
。我如何获得int值?或者如果可能的话直接返回int而不必使用ContentResult?
答案 0 :(得分:6)
我会做这样的事情:
public JsonResult Create(MyModel model)
{
return Json(new { Result = 1 });
}
using (Ajax.BeginForm("Create",
new AjaxOptions {
OnComplete = "function(data) { alert(data.get_response().get_object().Result); }"
}))