5

I am calling a controller method using Url.action like,

location.href = '@Url.Action("Display", "Customer", new { username = "abc",name = "abcdef",country = "India",email = "[email protected]",phone = "9456974545"})';

My controller method is,

public void Display(string username, string name, string country, string email, string phone)
{    }

In this method, I can get only the value of first parameter (username). Its not getting other parameter values that is passed. All other values are null.

Please suggest me, whats wrong?

5
  • Can you see the querystring parameters in browsers address bar when ActionLink is clicked? Commented Feb 14, 2013 at 6:13
  • Yes. I can see the querystring parameters in browsers address bar. The url is like this: localhost:60710/Customer/… Commented Feb 14, 2013 at 6:17
  • What is it ? Paste it here Commented Feb 14, 2013 at 6:18
  • localhost:60710/Customer/… Commented Feb 14, 2013 at 6:25
  • Hmm.. Try like this @Html.Raw(@Url.Action("Display","Customer", new { username = "abc",name = "abcdef"})) Commented Feb 14, 2013 at 6:28

2 Answers 2

7

By default every content (which is not IHtmlString) emitted using a @ block is automatically HTML encoded by Razor.

So, @Url.Action() is also get encoded and you are getting plain text. And & is encoded as &

If you dont want to Encode then you should use @Html.Raw(@Url.Action("","")).

The answer for you question is :

location.href = '@Html.Raw(@Url.Action("Display", "Customer", new { username = "abc",name = "abcdef",country = "India",email = "[email protected]",phone = "9456974545"}))';

Hope this helps

Sign up to request clarification or add additional context in comments.

Comments

1

There is a problem with '&' being encoded to the '& amp;'

model binder doesnt recognise this value. You need to prevent this encoding by rendering link with Html.Raw function.

Use '@Html.Raw(Url.Action......)'

Comments

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.