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?

2 Answers 2

3

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

<a href="<%= Url.Action("Index") %>?foo">Index</a>
Sign up to request clarification or add additional context in comments.

Comments

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?

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.