我有一个 mvc 项目。我在模式对话框中打开一个表单。用户填写表格并点击保存。表单发布到控制器但是我试图通过 json 拦截和发布。
查看开发工具网络部分以及在我的 json 中有 alert() 它没有运行,我认为它没有正确连接?我已经阅读了几页,看来我的 json 基本上是正确的。
我知道父页面和窗口之间存在关系......这是一个成为模式窗口的 div。但是,我不知道这是否是故障的一部分。
在父窗口中,这是我的模式是如何启动的。
$("#edit").click(function (e)
{
e.preventDefault();
var detailsWindow = $("#window").data("kendoWindow");
if (!detailsWindow)
{
// create a new window, if there is none on the page
detailsWindow = $("#window")
// set its content to 'loading...' until the partial is loaded
.html("Loading...")
.kendoWindow(
{
modal: true,
width: "800px",
height: "400px",
title: "@T("....")",
actions: ["Close"],
content:
{
url: "@Html.Raw(Url.Action("...", "..."))",
data: { ... }
}
}).data('kendoWindow').center();
}
detailsWindow.open();
});
上面的代码点击控制器并填充模型,然后按预期加载部分居中模式。
在模态部分我有这个:
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "formCreateEdit" }))
{
...HTML ELEMENTS...
<input type="submit" name="save" id="save" value="@T("...")" />
}
<script>
$(function()
{
$("#formCreateEdit").submit
(function (e)
{
alert(e);
e.preventDefault(); //As we will manually submit the form
$.ajax(
{
type: "POST",
url: "@Html.Raw(Url.Action("...", "..."))",
data: $(this).serialize(),
success: function (data)
{
//here we check if database called resulted in Success/Failure
if (data.Result === "Success")
{
alert('Finis');
}
else
{
//Show error message or whatever.
}
}
})
//});
});
</script>
编辑:
我也尝试过拦截按钮点击事件。我可能确实做错了,所以这是我尝试时的代码:
$('#save').click(function(event)
{
event.preventDefault();
// take over and perform ajax post
alert('ddd');
$.ajax(
{
type: "POST",
url: "@Html.Raw(Url.Action("...", "..."))",
data: $(this).serialize(),
success: function (data)
{
//here we check if database called resulted in Success/Failure
if (data.Result === "Success")
{
alert('Finis');
}
else
{
//Show error message or whatever.
}
}
})
});