Clean Url for MVC index method with parameter
I'm new to MVC and Google hasn't been much help so I will ask here. What I'm trying to do is simple (I would had thought) I want to pass a string to the ind开发者_开发百科ex method but it generally looks like:
http://mydomain.com/home/index/mystring
and I want:
http://mydomain.com/mystring
How do I go about that?
You could define the following route in Global.asax:
routes.MapRoute(
"MyStringRoute",
"{*mystring}",
new { controller = "Home", action = "Index" }
);
which will invoke the Index
action of the Home
controller:
public class HomeController : Controller
{
public ActionResult Index(string mystring)
{
return View();
}
}
精彩评论