C# ASP.NETMVC3-更改URL中间位置
假设我有这样一个动作:C# ASP.NETMVC3-更改URL中间位置,c#,asp.net,.net,asp.net-mvc,asp.net-mvc-3,C#,Asp.net,.net,Asp.net Mvc,Asp.net Mvc 3,假设我有这样一个动作: [HttpPost] public ActionResult(MyObject obj) { //Do a SQL insert that gets an Id for obj //Do some long-running operation in the background - don't wait for it to finish //Return a report of the object return View(obj); } 有没有办法
[HttpPost]
public ActionResult(MyObject obj)
{
//Do a SQL insert that gets an Id for obj
//Do some long-running operation in the background - don't wait for it to finish
//Return a report of the object
return View(obj);
}
有没有办法修改帖子后的URL,使其在末尾显示
?id=1234
?执行GET有一个等价的操作(就好像用户共享了页面一样),我只想显示报告。您应该使用重定向结果
并将用户重定向到新的URL
如果这样做,则无法将任何内容传递给视图
通常的做法是将其存储在TempData
变量中:
[HttpPost]
public ActionResult(MyObject obj)
{
//Do a SQL insert that gets an Id for obj
//Do some long-running operation in the background - don't wait for it to finish
TempData["obj"] 0 obj;
//Return a report of the object
return new RedirectResult();
}
无法通过编程从服务器更改URL。
如果您不想使用重定向,可以在页面加载后使用JavaScript对其进行更改我使用了您提到的JavaScript选项,我还不想运行新操作。