2013-02-14 19 views
3

我打电话使用Url.action像一个控制器的方法,只有使用Url.action调用控制器方法时,第一个参数值正在获取。

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

我控制器的方法是,

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

在这种方法中,我可以得到一个参数(username)才值。它没有获得传递的其他参数值。所有其他值都为空。

请建议我,最新怎么了?

+0

你能看到在浏览器中的查询字符串参数地址栏用户点击ActionLink什么时候? – 2013-02-14 06:13:24

+0

是的。我可以在浏览器地址栏中看到查询字符串参数。 url是这样的:http:// localhost:60710/Customer/Display?username = abc & name = abcdef & country = India & email = abc%40hmail.com & phone = 9456974545 – Kokila 2013-02-14 06:17:40

+0

这是什么?在这里贴吧 – 2013-02-14 06:18:33

回答

4

缺省情况下使用@块发出的每个内容(这是不IHtmlString)自动是HTML encoded通过剃刀。

因此,@Url.Action()也被编码,你会得到纯文本。 &编码为&

如果你不想编码,那么你应该使用@Html.Raw(@Url.Action("",""))

你问题的答案是:

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

希望这有助于

+0

非常感谢。 – Kokila 2013-02-14 06:47:36

+0

@Kokila Welcome – 2013-02-14 07:20:41

1

'&'被编码为'& amp;'时出现问题

模型活页夹不能识别这个值。您需要通过使用Html.Raw函数呈现链接来防止此编码。

使用 '@ Html.Raw(Url.Action ......)'

相关问题