【发布时间】:2013-10-25 19:15:42
【问题描述】:
我的网址是这样的,
localhost:19876/PatientVisitDetail/Create?PatientId=1
我必须从 URL 中检索 PatientId 并将其传递给请求。
我试过了,
Url.RequestContext.Values["PatientId"] => System.Web.Routing.RequestContext does not contain a definition for 'Values' and
no extension method 'Values' accepting a first argument of type 'System.Web.Routing.RequestContext'
我又试了,
RouteData.Values["PatientId"] => an object reference is required for the non static field, method
or property 'System.Web.Routing.RouteData.Values.get'
编辑:
根据下面 Jason 的评论,我尝试了 Request["SomeParameter"] 并且成功了。但是,也有一个警告要避免这种情况。
任何想法如何在我的场景中避免这种情况?
我的场景:
我的控制器中有一个Create 操作方法用于创建新患者。
但是,我需要回到最后一页,
如果我给出类似的东西,
@Html.ActionLink("Back to List", "Index")
=> this wont work because my controller action method has the following signature,
public ActionResult Index(int patientId = 0)
所以,在这种情况下,我必须传递patientId。
【问题讨论】:
-
因为
PatientId是一个查询字符串参数,看看这个:stackoverflow.com/questions/2888105/… -
@JasonEvans:感谢您的链接。有效。但是,我也看到了一个警告,即
do not access the url parameters in the view?。在我的情况下,如何避免这种情况?
标签: c# url asp.net-mvc-4 .net-4.0 routing