我有以下引导箱片段,我在其中通过 ajax 调用加载消息:
$.ajax({
type: "GET",
url: $("#add-name").val(),
success: function (data) {
bootbox.dialog({
message: data,
title: "Floorplan Group",
buttons: {
success: {
label: "OK",
className: "btn-success",
callback: function () {
//what to do here?
}
}
}
});
}
});
这就是data
返回的内容,并加载到我的引导框对话框的正文中。
@model Monitoring.ViewModels.NameViewModel
@using (Html.BeginForm("AddName", "Users", FormMethod.Post, new {@class = "form-horizontal",}))
{
@Html.EditorFor(m => m.Name)
}
这是我的控制器:
[HttpPost]
public ActionResult AddName(NameViewModel model)
{
if (!ModelState.IsValid)
{
//return error
}
//add into DB
return View(model);
}
如何将表单发布回我的控制器?bootbox 的回调中需要什么代码才能将我的表单发回,如果 ModelState 中有任何错误,我的 bootbox 对话框将保持打开状态,否则对话框将正常关闭。