ASP.NET MVC passing an ID in an ActionLink to the controller

前端 未结 5 1718
故里飘歌
故里飘歌 2020-12-07 20:03

I can\'t see to retrieve an ID I\'m sending in a html.ActionLink in my controller, here is what I\'m trying to do

  • <%= Html.ActionLink(\"Mod
  • 相关标签:
    5条回答
    • 2020-12-07 20:08

      Doesn't look like you are using the correct overload of ActionLink. Try this:-

      <%=Html.ActionLink("Modify Villa", "Modify", new {id = "1"})%>
      

      This assumes your view is under the /Views/Villa folder. If not then I suspect you need:-

      <%=Html.ActionLink("Modify Villa", "Modify", "Villa", new {id = "1"}, null)%>
      
      0 讨论(0)
    • 2020-12-07 20:13

      The ID will work with @ sign in front also, but we have to add one parameter after that. that is null

      look like:

      @Html.ActionLink("Label Name", "Name_Of_Page_To_Redirect", "Controller", new {@id="Id_Value"}, null)
      
      0 讨论(0)
    • 2020-12-07 20:16

      On MVC 5 is quite similar

      @Html.ActionLink("LinkText", "ActionName", new { id = "id" })
      
      0 讨论(0)
    • 2020-12-07 20:17

      In MVC 4 you can link from one view to another controller passing the Id or Primary Key via

      @Html.ActionLink("Select", "Create", "StudentApplication", new { id=item.PersonId }, null) 
      
      0 讨论(0)
    • 2020-12-07 20:18

      Don't put the @ before the id

      new { id = "1" }
      

      The framework "translate" it in ?Lenght when there is a mismatch in the parameter/route

      0 讨论(0)
    提交回复
    热议问题