Empty query string parameters with ASP.NET MVC
-
18-09-2019 - |
Question
Is it possible to add "empty" query string parameters with ASP.NET MVC? I need to somehow generate the following url using Html.ActionLink
:
/Home/Index?foo
However this Html.ActionLink("Index", "Index", new {foo = ""})
will output
/Home/Index
Is this possible at all?
Solution
You may have to use Url.Action() instead of Html.ActionLink.
<a href="<%= Url.Action("Index") %>?foo">Index</a>
OTHER TIPS
Now that I understand your problem a little more, no I do not think there is a way to force the ActionLink() function to have an empty string valued query string parameter.
So the next question is... are there any semantic issues with converting a null value for foo
to an empty string?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow