简体   繁体   中英

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

I want to parse data from a URL string at ASP.NET MVC 5. Here are the important lines.

Index.cshtml :

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

Browers Line

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

create.cshtml :

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

The values from "id" is "6" but the value from "status" is null.

What I have to do get the "1" from the URL string?

There are a few possibilities:

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

In.Net Core it seems like you have to use:

Context.Request.Query["status"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM