0

当我使用以下操作链接时:

<%: Html.ActionLink("Study Cases", "Index", "CourseCases", new { id = Model.ID }, new { @class = "t-button", @style = "width:240px; color:white; text-align:center" })%>

浏览器中的url地址为:

http://localhost:11111/CourseCases/Index/9

我怎样才能改变它,所以 url 将是

 http://localhost:11111/CourseCases?courseId=9

它在我使用时有效:

 return RedirectToAction("Index", "CourseCases", new { courseId = id });

在控制器中。非常感谢。

4

1 回答 1

0

像这样:

<%= Html.ActionLink(
    "Study Cases", 
    "Index", 
    "CourseCases", 
    new { courseId = Model.ID }, 
    new { 
        @class = "t-button", 
        @style = "width:240px; color:white; text-align:center" 
    }
) %>

您的代码生成的原因http://localhost:11111/CourseCases/Index/9是因为{id}在您创建 ASP.NET MVC 3 应用程序时生成的默认路由使用它,因此当您指定id = Model.ID它时,它将与您的 Global.asax 中的路由模式定义匹配,{controller}/{action}/{id}因此您得到CourseCases/Index/9.

于 2012-05-22T21:50:05.350 回答