URL.Action() including route values

前端 未结 2 1280
长发绾君心
长发绾君心 2020-12-13 03:29

I have an ASP.Net MVC 4 app and am using the Url.Action helper like this: @Url.Action(\"Information\", \"Admin\")

This page is used for both adding a ne

相关标签:
2条回答
  • 2020-12-13 04:10

    You also can use in this form:

    <a href="@Url.Action("Information", "Admin", null)"> Admin</a>

    0 讨论(0)
  • 2020-12-13 04:14

    outgoing url in mvc generated based on the current routing schema.

    because your Information action method require id parameter, and your route collection has id of your current requested url(/Admin/Information/5), id parameter automatically gotten from existing route collection values.

    to solve this problem you should use UrlParameter.Optional:

     <a href="@Url.Action("Information", "Admin", new { id = UrlParameter.Optional })">Add an Admin</a>
    
    0 讨论(0)
提交回复
热议问题