开发者

ASP.NET MVC A problem with routing

开发者 https://www.devze.com 2023-01-28 04:04 出处:网络
how should my Global.asax file look, and the Controller\'s action, to get a URL like: http://mysite.com/name

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

精彩评论

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