2

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?

Atanas Korchev
  • 30,562
  • 8
  • 59
  • 93

2 Answers2

3

You may have to use Url.Action() instead of Html.ActionLink.

<a href="<%= Url.Action("Index") %>?foo">Index</a>
Matt
  • 41,216
  • 30
  • 109
  • 147
1

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?

Nick Larsen
  • 18,631
  • 6
  • 67
  • 96
  • Yes, I want to handle null in a different way from empty string to avoid passing some dummy values such as space or anything else. I think the other response is the way to go. – Atanas Korchev Feb 06 '10 at 08:15