C#mvc3 Actionlink不在URL中发送参数

时间:2012-12-12 15:57:17

标签: c# asp.net-mvc-3

我在MVC3和Actionlink方面遇到了一些问题。我正在使用从我的模型传递的数据动态构建HTML ActionLink

在视图中:

@for (int i = 0; i < Model.CountriesList.Count; i++)
{

<li class="sub">@Html.ActionLink(Model.CountriesList[i].countryname, 
                                 "PageSub", new { PageID = Model.PageNo, 
                                                  countryid = Model.CountriesList[i].countryid 
                                                 })</li>

}

Model.PageNo从控制器传递并具有值。我测试了这个。每次我点击链接时都会收到错误,因为PageNo没有作为参数传递。网址输出如下:

http://localhost/Pages/PageSub?countryid=196

当我直接输入它时,我需要它在下面工作:

http://localhost/Pages/PageSub?PageID=136&countryid=196

这是我的Controller ActionResult,它指向:

public ActionResult PageSub(int? PageID, int? countryid)
{

}

我已使用开发人员工具检查了代码,并且已按预期构建链接:

<li class="sub">
     <a href="/Pages/PageSub?PageID=136&countryid=196">
</li>

有没有人有类似的问题?任何意见,将不胜感激。感谢

1 个答案:

答案 0 :(得分:0)

试试这个:

@Html.ActionLink(Model.CountriesList[i].countryname, "PageSub", "Pages", new { PageID = Model.PageNo, countryid = Model.CountriesList[i].countryid }, null)