我需要在成功创建的案例记录中传递来自控制器方法的json响应,并希望在成功函数或完成中的ajax中警告此消息,但由于某种原因我未能实现此目的。
$('#NewFunctionNavigationForm').submit(function (e) {
e.preventDefault();
var DataToPost = JSON.stringify($('#NewFunctionNavigationForm').serializeObject());
var formURL = $(this).attr("action");
$.ajax({
type: "POST",
url: formURL,
dataType: "JSON",
contentType: "application/json; charset=utf-8",
data: DataToPost,
})
.done(function (data, textStatus, jqXHR) { alert("Success: " + response); })
.fail(function (jqXHR, textStatus, errorThrown) { alert("Error"); })
.always(function (jqXHROrData, textStatus, jqXHROrErrorThrown) { alert("complete"); });
});
#region CreateNewFunctionNavigation
[HttpGet]
public ActionResult CreateNewFunctionNavigation()
{
return PartialView("CreateNewNavigation_Partial");
}
#endregion
[HttpPost]
public ActionResult CreateNewFunctionNavigation(CreateFunctionNavigation_SP_Map model )
{
if(ModelState.IsValid)
{
try
{
_FN_Services_a2.CreateFunctionNavigation(model);
return Json(new { Response = "Success" });
}
catch (DataException ex)
{
ModelState.AddModelError("", "Unable To Create New Function Navigation" + ex);
}
}
return PartialView("CreateNewNavigation_Partial", model);
//return Json(new { Url = Url.Action("CreateNewNavigation_Partial", model) });
} //end
答案 0 :(得分:1)
纠正完成的功能应该有效。请尝试以下代码:
.done(function (data, textStatus, jqXHR) { alert("Success: " + data.Response ); })
如果您遇到任何问题,请告诉我。