Reputation: 461
There is a project works like:
/node.aspx?id=1
/node.aspx?id=2
I need to change it to:
/node/1
/node/2
I have providing new mvc project and here is my controller:
public ActionResult node(string id)
{
return View("~/node.aspx");
}
And this is my RouteConfig:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { action = "Index", id = UrlParameter.Optional }
);
Such a code works fine, but on case adding "id", it's not works anymore:
public ActionResult node(string id)
{
return View("~/node.aspx?id=" + id);
}
Error:
The view '/node.aspx?id=2' or its master was not found or no view engine supports the searched locations.
Is there any way to show old page like "aspx?id.." on the router?
Upvotes: 1
Views: 62
Reputation: 637
To pass data from controller to view you need to use ViewBag. The View method will only accept file name or file path and query strings not allowed.
So to pass the id from controller to view you can use ViewBag as below. Further you can read here to use ViewBag
ViewBag.Id = id;
Also, ViewBag’s scope is available in Request Context so there will not be any issue with multiple request.
Upvotes: 1