[英]update field or redirect page using jquery and asp.net mvc
Im new to jquery and stuck with what i want to achieve. 我是jquery的新手,并且坚持要实现的目标。 Heres what I want to do using jquery and asp.net mvc. 这是我想使用jquery和asp.net mvc做的事情。
so far I tried this: 到目前为止,我尝试了这个:
$("#submit")
.button()
.click(function () {
$.ajax({
type: "POST",
url: "Account/LogOn",
dataType: "json",
success: function (data, textStatus) {
if (data.redirect) {
// data.redirect contains the string URL to redirect to
window.location.href = data.redirect;
}
else {
// data.form contains the HTML for the replacement form
$("#error2").replaceWith(data.error);
}
}
});
});
how do I construct the relevant bits in the action method? 如何构造动作方法中的相关位? to make this work? 使这项工作? and is the jquery code ok? jQuery代码还可以吗? i suspect prob not. 我怀疑没有。
Thanks 谢谢
If you want to redirect asp.net page at same directory , you can by Jquery/Java script by this : 如果要重定向同一目录中的asp.net页面,可以通过Jquery / Java脚本执行以下操作:
$("#ctl00_iframecontent_BtnCancle").click(function () {
window.location = "IncSLAList.aspx?bi=37";
});
and To redirect to Another page of project , can use : 和重定向到项目的另一页,可以使用:
window.location.href = "http://ImageUpload/Welcome.aspx?
Your jQuery is almost correct: 您的jQuery几乎是正确的:
.button()
(unless you're using jQuery UI and want to do that) 不要调用.button()
(除非您正在使用jQuery UI并且想要这样做) return false;
添加return false;
at the end of the click
handler to prevent the browser from submitting normally. 在click
处理程序的末尾,以防止浏览器正常提交。 In the action, you would either return Json(new { redirect = str })
or return Json(new { error = str })
. 在操作中,您将return Json(new { redirect = str })
或return Json(new { error = str })
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.