我有一个mvc项目,我想做的是:
我正在从我的JS脚本发送一个ajax请求。在处理完它之后,我想重定向到带有模型的页面。
现在,我尝试发送一个表单作为ajax响应,并按如下方式提交:
sb.Append("<html>");
sb.AppendFormat(@"<body onload='document.forms[""form""].submit()'>");
sb.AppendFormat("<form name='form' action='{0}' method='post'>", "url..");
sb.AppendFormat("<input type='hidden' name='result' value='{0}'>", val1);
.....在JS上:
success: function (result) {
var form = $(result);
$(form).submit();
}但是这样我需要指定每个post param,我想发送整个模型对象。我怎么能这么做?
编辑完整步骤:
1.使用MVC应用程序。
2.在我的视图中提交按钮,将用户重定向到我的JS代码。
3.Js代码向名为“Transaction”的MVC页面发送Ajax请求。
4.C#代码执行一些操作,现在我需要将usr重定向到一个名为EOF的页面,其中包含post params的ALOT,这就是为什么我想将它作为ViewModel传递。
发布于 2014-08-06 08:11:28
在使用ajax时,可以从操作中返回URL,并在javascript中重定向它:
控制器
public ActionResult Transaction()
{
// Do stuff
return Json(new { success = true, redirecturl = Url.Action("RedirectedAction") });
}然后在javascript中向成功处理程序添加类似的内容:
Javascript (在成功处理程序中)
success: function (result) {
if (result.success == true)
{
window.location = result.redirecturl;
}
}发布于 2014-08-06 07:27:43
你可以试试这个:
public ActionResult YourMethod(string param)
{
//what ever you want to do with reference no
return View("EOF");
// or, if you want to supply a model to EOF:
// return View("EOF", myModel);
}https://stackoverflow.com/questions/25154055
复制相似问题