Only first parameter value is getting while calling controller method using Url.action.
Asked Answered
G

2

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?

Grati answered 14/2, 2013 at 5:49 Comment(5)
Can you see the querystring parameters in browsers address bar when ActionLink is clicked?Mccartan
Yes. I can see the querystring parameters in browsers address bar. The url is like this: localhost:60710/Customer/…Grati
What is it ? Paste it hereMccartan
localhost:60710/Customer/…Grati
Hmm.. Try like this @Html.Raw(@Url.Action("Display","Customer", new { username = "abc",name = "abcdef"}))Mccartan
M
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

Mccartan answered 14/2, 2013 at 6:33 Comment(0)
T
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......)'

Ty answered 14/2, 2013 at 6:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.