2009-07-28 54 views
0

所以我有一个自定义路由这样:asp.net的MVC定制路由提交按钮

routes.MapRoute(
      "Wizard", // Route name 
      "Wizard/{page}", // URL with parameters 
      new { controller = "Wizard", action = "Index" } // Parameter defaults 
     ); 

,并且对我查看以下内容:

<% Html.BeginForm("Continue", "Wizard"); %> 
    <input type="submit" value="Continue" name="Continue" /> 
<% Html.EndForm(); %> 

在这我要打电话此功能:

[AcceptVerbs(HttpVerbs.Post)] 
    public ActionResult Continue(string Number, string Rev) 
    { 
     (...) 
    } 

但反过来当按下该按钮时总是调用回发索引而不是我想要的。如果我删除了自定义路由,它会调用我的函数,但是我想要在地址栏中显示的内容是:localhost:xxxx/Wizard/1其中最后的数字是向导的页面(显示div),也可以是1 ,2,3或4.那么有什么我失踪或不能完成?谢谢。

回答

0

你应该改变你的路线,这样的行动是参数:

routes.MapRoute(
    "Wizard", // Route name 
    "Wizard/{action}", // URL with parameters 
    new { controller = "Wizard", action = "Index"} // Parameter defaults 
); 

关于你的问题的其余部分,请你能详细点吗?

0

在HTML什么是被写入了现在(form标签)?

你预计页码从何而来?我没有看到你是如何使它成为网址的一部分。 (而且因为它不是URL的一部分,它会导致路由不匹配。)你需要使它的路线的一部分,如:

<%= Html.BeginForm("Continue", "Wizard", new { page = intPage }) %> 

另外,我还不能肯定的是,默认FormMethod是POST。您可能需要在表单标记中仔细检查。

詹姆斯