Answer the question
In order to leave comments, you need to log in
How to implement a route in ASP.net MVC?
Tell me how to implement the following address:
site/{parametr}
That is, it is necessary that the parameter be immediately passed to the Index action and if parametr=index then the main page is displayed, and in other cases another view is loaded
Answer the question
In order to leave comments, you need to log in
Good afternoon!
If I understand you correctly, the route would be:
routes.MapRoute(
name: "",
url: "site/{parametr}",
defaults: new { controller = "Home", action = "Index", parametr = "index" }
);
routes.MapRoute(
name: "",
url: "",
defaults: new { controller = "Home", action = "Index", parametr = "index" }
);
public ActionResult Index(string parametr)
{
if(parametr != null)
{
switch(parametr)
{
case "index":
return View();
default:
//return RedirectToAction("IndexOther", "Home");
//или
return View("IndexOther");
}
}
// Здесь что-то происходит...
return View();
}
public ActionResult Index(string parametr = "index")
{
switch(parametr)
{
case "index":
return View();
default:
//return RedirectToAction("IndexOther", "Home");
//или
return View("IndexOther");
}
// Здесь что-то происходит...
return View();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question