开发者

ASP.NET MVC A problem with routing

how should my Global.asax file look, and the Controller's action, to get a URL like:

http://mysite.com/name

The name is a string - it may be anything.

I try:

Global开发者_运维技巧.asax:

routes.MapRoute(
                "ViewContent",   // Route name
                "{name}",     // URL with parameters
                new { controller = "Main", action = "ViewC" }  // Parameter defaults
            );

MainController:

public ActionResult ViewC(string name)
{
    ...
}

but it doesn't "go" inside that action.


try

    routes.MapRoute("Default", "{name}",
                    new {.controller = "Main",
                         .action = "ViewC",
                         .name = UrlParameter.Optional});

You might also want to make that controller return the view "name"

public ActionResult ViewC(string name)
{
    return view(name);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜