Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 259
Kokila Avatar asked Feb 14 '13 05:02

Kokila


2 Answers

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

like image 113
Karthik Chintala Avatar answered Oct 22 '22 08:10

Karthik Chintala


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......)'

like image 35
Michal Franc Avatar answered Oct 22 '22 07:10

Michal Franc