开发者

ASP.NET MVC 2 controller-url problems

I am still very new to the MVC开发者_Go百科 framework, but I managed to create a controller that reads from a database and writes JSON to an url;

host.com/Controllername?minValue=something&maxValue=something

However when I move the site to a subfolder;

host.com/mvc/

it doesn't seem to be able to call the controller from there when I do it like this;

host.com/mvc/Controllername?minValue=something&maxValue=something

Did I forget to do something somewhere to make this url call valid from that subfolder? Any help here would be greatly appreciated.


In the first case you are specifying the controller name while in the second case you are not. You could setup a default route:

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new
    {
        controller = "Controllername",
        action = "ActionName",
        id = UrlParameter.Optional
    }
);

Once this default route points to the controller and action both urls should work:

host.com/?minValue=something&maxValue=something
host.com/mvc/?minValue=something&maxValue=something
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜