I'm currently learning asp.net core, so tried to add RouteData to my mvc model and pass it to view, however when I count the number of Data values ( @Model.Data.Count
) it returns 0. I don't want to use ViewBag or @ViewContext.RouteData.Values[key]
in my view code.
mvc route
app.UseMvc(route =>
{
route.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}/{*catchall}");
});
my action method
public ViewResult List(string id)
{
var r = new Result
{
Controller = nameof(HomeController),
Action = nameof(List),
};
// var catch=RouteData.Values["catchall"]; this line is working fine
r.Data["id"] = id ?? "<no value>";
r.Data["catchall"] = RouteData.Values["catchall"];
//when I checked r.Data.count it returns 0 even in here
return View("Result", r);
}
and my view
@model Result
.
.
@foreach (var key in Model.Data.Keys)
{
<tr><th>@key :</th><td>@Model.Data[key]</td></tr>
}