我的網址URL值是一樣的東西,獲得 「ID」 從MVC 4
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'
編輯:
基於傑森的評論下面,我想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'是查詢字符串參數,請看看這個:http://stackoverflow.com/questions/2888105/how-to-access-querystring-in-asp-net-mvc-view –
@JasonEvans :感謝您的鏈接。有效。但是,我也看到一個警告,「不訪問視圖中的url參數?」。在我的情況下,如何避免這種情況? –