I just made a new route:
routes.MapRoute(
name: "example",
url: "{example}/{details}/{id}",
defaults: new { controller = "example", action = "Index", id = UrlParameter.Optional }
);
The route works fine but I do not know how to reference which "id" I am currently on so I can display the correct information on my "details" view page for said "id" on my route.
For more context, I have my base "example" page where I am displaying users from a database and each has an "ID" associated with them, when their names are clicked, it then grabs said "ID" and goes to /example/details/{user id I just clicked on} (this works) now I need to know how to show the users info for said route.
Controller:
public ActionResult Details()
{
var example = from a in db.Example
where a.ExamplePresent
orderby a.ExampleName
select a;
return View(example.ToList());
}
View:
@model List<Example.Areas.ExamplePage.Models.Example>
@{
ViewBag.Title = "Example Page";
}
If you don't want to create a viewmodel for this case, you can pass the id parameter and list to the view via tuple and reference it in the view as follows:
view
And your example list is:
A more proper way would be creating a view model for details view and pass your values via the view model:
viewmodel:
action:
view: