How to pass query string parameter in ActionLink in MVC

后端 未结 4 583
悲&欢浪女
悲&欢浪女 2021-02-03 16:52

I am having following action link:

<%= Html.ActionLink(\"Check this\", \"Edit\", \"test\", 
                     new { id = id }, new { style = \"display:bloc         


        
4条回答
  •  后悔当初
    2021-02-03 17:37

    4th parameter of Html.ActionLink can have any number of properties:

    <%= Html.ActionLink("Check this", "Edit", "test", 
                         new { id = id, data=name }, new { style = "display:block" })%>
    

    These properties are inserted into URL based on routing, but if the property name cannot be matched into any route it is added as URL GET parameter.

    So if you have standard route {controller}/{action}/{id}, you will get the URL:

    test/Edit/[id]?data=[name] 
    

    from the above code.

提交回复
热议问题