如何让JQuery返回View?
以前,我让表单直接调用 Action,但现在,我想在调用 Action 之前使用 JQuery 来做一些事情。我遇到的问题是,之前,当我从控制器调用 return View() 时,它会使用我放入 Viewbag.Message 的消息重新加载部分页面。我如何使用 JQuery 做到这一点?
$("#button").click(function () {
DoStuff();
});
function DoStuff()
{
$.ajax("Home/DoStuff"), function() {
};
}
$
[HttpPost]
public ActionResult DoStuff()
{
string value = Request.Form["value"];
Viewbag.Message = TempData["message"];
CustomView view = new CustomView();
return View(view);
}
Before, I had my form directly call the Action, but now, I want to use JQuery to do stuff before having the Action called. The problem I have is that before, when I called return View() from the controller, it would reload the partial page with the message I put into the Viewbag.Message. How do I do that with JQuery?
$("#button").click(function () {
DoStuff();
});
function DoStuff()
{
$.ajax("Home/DoStuff"), function() {
};
}
$
[HttpPost]
public ActionResult DoStuff()
{
string value = Request.Form["value"];
Viewbag.Message = TempData["message"];
CustomView view = new CustomView();
return View(view);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑这样的事情(未测试):
部分视图DoStuff.cshtml:
操作:
Consider something like this (not tested):
Partial View DoStuff.cshtml:
Action: