How to get id value in controller / action / id

I have a view of an editing application and can be found at the following URL:

http: // localhost: 17262 / Application / EditApplication / 1

1 is equal to the application identifier.

Also on the page I have a link that goes into another view to add an assistant for the application. I want to give him the application identifier so that the new assistant can be “bound” to this application. How do I get a value of 1 and add it to my action link? This is what I have in my HTML so far:

<%: Html.ActionLink("Add New Assistant", "Create", "Assistant", new { applicationID = "id" }, null) %>

Please can anyone advise?

thank

+3
source share
1 answer

Request.RequestContext.RouteData.Values["id"]

, .

ViewData​​p >

ViewData["applicationID"] = 1; //or ApplicationModel.Id or whatever

<%: Html.ActionLink("Add New Assistant", "Create", "Assistant", new { applicationID = ViewData["applicationID"] }, null) %>

viewmodel id:

<%: Html.ActionLink("Add New Assistant", "Create", "Assistant", new { applicationID = Model.ApplicationID }, null) %>
+5

Source: https://habr.com/ru/post/1766367/


All Articles