首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

请问@Html.ActionLink的使用有关问题

2013-07-04 
请教@Html.ActionLink的使用问题请教在Index.cshtml中有代码p@Html.ActionLink(测试, Test, Index

请教@Html.ActionLink的使用问题
请教在Index.cshtml中有代码
<p>@Html.ActionLink("测试", "Test", "Index", new { id = 1 }) </p>
怎么运行时输出的HTML代码是:
<p><a href="/Test?Length=5" id="1">测试</a> </p>

按理应该是
<p><a href="/Test?id=1">测试</a> </p>
[解决办法]

<p>@Html.ActionLink("测试", "Home", "Index", new { id = 1 },null) </p>

[解决办法]
引用:
<p>@Html.ActionLink("测试", "Home", "Index", new { id = 1 },null) </p>

+1,正解
[解决办法]
引用:
<p>@Html.ActionLink("测试", "Home", "Index", new { id = 1 },null) </p>
生成的是
<p><a href="/Home/1">测试</a> </p>
而不是
<p><a href="/Home?id=1">测试</a> </p>      ==>我要传递参数


这只是形式的问题,你改一下Route,把里面的id换成其他的名称,比如id1等,就可以得到后面的形式了,或者你修改ActionLink里面的参数名称,就不用改Route了。
[解决办法]
 @Html.ActionLink("测试", "Test", new { myID = 1 })

不能用id,因为ActionLink有id属性

热点排行