开发者

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();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜