ASP.NET MVC ActionResult View()不更改url

Bri*_*man 2 c# asp.net asp.net-mvc actionresult asp.net-mvc-2

我有一个方法......

[HttpPost]
public ActionResult Start(SomeViewModel someViewModel) { ... }
Run Code Online (Sandbox Code Playgroud)

是基于一些条件返回之类的东西回报View("Invalid"),View("NotFound"),View("Run", anotherViewModel),等的问题是,无论我提出什么观点,URL不会更改以反映新的控制器/行动.当我的View想要发布到不同的操作时,这会产生问题.我怎样才能解决这个问题?

Ser*_*ier 11

如果要更改URL,则需要重定向到与该URL关联的操作,例如

[HttpPost] 
public ActionResult Start(SomeViewModel someViewModel) 
{
  ...
  return RedirectToAction("SomeOtherAction");
}
Run Code Online (Sandbox Code Playgroud)

该操作SomeOtherAction将依次显示视图.


Mat*_*ott 8

这些View(...)方法不会重定向,只是呈现当前请求的特定视图.如果您需要以视图的形式定位特定网址,则可以将控制器/操作详细信息传递给表单方法:

Html.BeginForm("action", "controller")
Run Code Online (Sandbox Code Playgroud)

......等