C# 是否可以在同时返回视图时更改URL?这是没有重定向的吗?

C# 是否可以在同时返回视图时更改URL?这是没有重定向的吗?,c#,asp.net,asp.net-mvc,url,redirect,C#,Asp.net,Asp.net Mvc,Url,Redirect,在ASP.NET MVC中,我有一个看起来像这样的控制器: public class MyController{ public ActionResult Index(){ return View(new MyModel()); } [HttpPost] public ActionResult Index(MyModel model){ //do something return View("RegistrationC

在ASP.NET MVC中,我有一个看起来像这样的控制器:

public class MyController{
    public ActionResult Index(){
        return View(new MyModel());
    }
    [HttpPost]
    public ActionResult Index(MyModel model){
        //do something
        return View("RegistrationConfirmation", new ConfirmModel());
    }
    [HttpPost]
    public ActionResult RegistrationConfirmation(ConfirmModel model){
        //do something else
        return View();
    }
}
我想要的用户工作流程如下

  • 获取
    页面索引。返回视图
    索引
    。URL:
    ~/My
  • POST
    索引页中的数据-返回视图
    注册确认
    ,并将用户发送到右侧页面
    ~/My/RegistrationConfirmation
  • 用户在
    RegistrationConfirmation
    页面上发布另一个数据,以便调用
    RegistrationConfirmation
    来处理它们
现在操作方法
RegistrationConfirmation
从未被调用,因为在返回
RegistrationConfirmation
按索引查看操作方法URL保持
~/My
,因此第二篇文章由
索引(MyModel)
操作方法而不是
注册确认(ConfirmModel)处理
操作方法

如何在发送视图的同时更改URL,以便在
POST
返回时调用与视图对应的控制器操作?或者有没有其他方法来确保调用相应的控制器



注意:在发布这篇文章之前,我已经阅读了20多个似乎与主题相关的问题。我不认为任何一个完美的答案都能给我答案。请在投票前正确阅读,以重复方式关闭。

在查看注册确认中尝试此选项

您可以很容易地添加操作和控制器,这应该是Html.BeginnForm命令中的目标

   <% using(Html.BeginForm("RegistrationConfirmation", "MyController")){%>

    //form elements

   <%}%>

//形式元素

这样,您就可以准确地定义将调用哪个操作和控制器了

昨晚我遇到了类似的问题。这个答案就是我如何修复它的。在BegNotify中,您可以指定任何控制器和任何操作来处理您的帖子。谢谢!工作。在我的例子中,我必须向BeginForm的url参数添加一个ID,如Html中所述?