Search code examples
c#asp.netasp.net-mvcrazor

How do I remove a query string from an Html.ActionLink?


I have an Html.ActionLink helper that is passing an unexpected query string of ?Length=4. This is a problem for me because I need to pass my own string.

I am unable to use the route values parameter of the Html.ActionLink in this situation because the value I need to pass is a user selected javascript value from the rendered page.

How do I prevent this unexpected string from being passed?

This is my ActionLink:

@Html.ActionLink("Edit Attendees", "Attendees", "Smrt", new { @class= "btn btn-outline-secondary mr-2" })

This is the result:

http://localhost:55577/Smrt/Attendees?Length=4

Solution

  • I discovered that if I add the argument parameter for route values as a 'null' it removes this unexpected query string.

    @Html.ActionLink("Edit Attendees", "Attendees", "Smrt", null , new { @class= "btn btn-outline-secondary mr-2" })
    

    this then allowed me to pass the parameter I needed via jQuery.