簡體   English   中英

ASP.NET MVC 5 路由 - 創建 Html.ActionLink 並解析 ViewContext.RouteData.Values

[英]ASP.NET MVC 5 routing - create Html.ActionLink and parse ViewContext.RouteData.Values

我想從 ASP.NET MVC 5 處的 URL 字符串中解析數據。這是重要的幾行。

Index.cshtml

@Html.ActionLink(Name, ActionName, new { id = 6, status = 1 })

瀏覽器線

http://localhost/somthing/6?status=1

create.cshtml

@ViewContext.RouteData.Values["id"]     
@ViewContext.RouteData.Values["status"]

“id”的值為“6”,但“status”的值為 null。

我必須做什么才能從 URL 字符串中得到“1”?

有幾種可能:

Request.QueryString["status"];
Request.Params["status"];

在.Net Core 中,您似乎必須使用:

Context.Request.Query["status"];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM