在 ASP.Net MVC 3.0 中我使用 Ajax.Beginform
并点击 JsonResult
表单成功后我将调用 jQuery 函数。
但由于某种原因我的表单重定向到 JsonAction
my View
@using (Ajax.BeginForm("ActionName", "Controller", null, new AjaxOptions
{
HttpMethod = "POST",
OnSuccess = "ShowResult"
}, new { id = "myform" }))
{
// All form Fields
<input type="submit" value="Continue" class="button standard" />
}
我的控制器
public JsonResult ActionName(FormCollection collection)
{
return Json(new { _status },JsonRequestBehavior.AllowGet);
}
jQuery
<script type="text/javascript">
function ShowResult(data) {
// alert("I am at ShowResult");
if (data.isRedirect) {
window.location.href = json.redirectUrl;
}
}
由于某种原因,当我点击提交时。
它运行 JsonResult 并将页面重定向到 host/controller/actionname
我已经包括了我的
<script src="@Url.Content("jquery.unobtrusive-ajax.min.js")"></script>
在我的layout.cshtml中
谁能告诉我可能出了什么问题吗?
我发现了问题。现在我必须找到解决方案
提交时
我正在验证我的表格
$("#myform").validate({
submitHandler: function (form) {
// my logic goes here....
}});
如果我排除验证 Ajax 表单按预期工作。
但是如果我验证我的表单,那么 ajax 表单将无法按预期工作
谢谢