【发布时间】:2010-08-18 17:28:02
【问题描述】:
我的操作中有这样的链接
<%: Html.ActionLink("View Data","Index","MyItem", new {itemId=Model.itemId}, null)%>
现在在我的 newItem 控制器的索引操作中,我如何检索这个 itemId,到目前为止我已经尝试过 这个
public ActionResult Index()
{
RouteData rd = this.RouteData;
var list = from p in rd.DataTokens.Where(p => p.Key == "itemId") select p;
int? id = null;
if (list.Count() > 0)
id = Convert.ToInt32(list.Single().Value);
if (id.HasValue)
{
return View(from a in _Service.List().Where(a => a.ApplicantId == id.Value) select a);
}
else
return View(NORECORDVIEW,);
}
还有这个
HttpRequestBase rd = this.Request;
var list = from p in rd.QueryString.AllKeys.Where(p => p. == "itemId") select p;
int? id = null;
if (list.Count() > 0)
id = Convert.ToInt32(list.Single().Value);
if (id.HasValue)
{
return View(from a in Service.List().Where(a => a.ApplicantId == id.Value) select a);
}
else
return View(NORECORDVIEW);
但是这些都没有返回正确的值。
在 mvc1 中,我们可以轻松地直接处理,但请在 mvc2 中做到这一点。
【问题讨论】:
-
我不太清楚你想要完成什么......你为什么不能这样做:ActionResult Index(int? id)
标签: asp.net-mvc asp.net-mvc-2 dictionary routes