开发者

ASP.NET MVC 2 controller-url problems

开发者 https://www.devze.com 2022-12-27 05:20 出处:网络
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;

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

精彩评论

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