在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;
}
}
由于某些原因,当我单击submit时。它运行JSonResult并将页面重定向到我所包含的主机/控制器/动作名
<script src="@Url.Content("jquery.unobtrusive-ajax.min.js")"></script>
在我的layout.cshtml里
谁能告诉我出什么事了吗?
我发现了问题。现在我必须在提交时找到解决方案,我正在验证我的表单。
$("#myform").validate({
submitHandler: function (form) {
// my logic goes here....
}});
如果排除验证,Ajax表单将按预期工作。但是,如果我验证我的表单,那么ajax表单就不能像预期的那样工作了,谢谢
发布于 2011-11-25 12:49:40
当这种情况发生时,几乎总是因为您的脚本文件没有加载
注:
http://completedevelopment.blogspot.com/2011/02/unobstrusive-javascript-in-mvc-3-helps.html
~/Scripts/jquery-1.4.4.js
上挂起此魔术的库的引用
因此,加载http://fiddler2.com并查看脚本是否被调用和加载。
https://stackoverflow.com/questions/8273819
复制相似问题