为什么我的MVC路由注册不起作用

时间:2012-04-01 07:28:46

标签: c# .net asp.net-mvc asp.net-mvc-routing global-asax

我有

控制器:

[MySite]\Controllers\DistributionTools\TrackingChannelsController.cs

[HttpPost]
public void InitTcFirstPageView()
{
    var model = new TcFirstPageModel
                    {
                        BestChannel = new BestChannel()
                    };
    View("~\\Views\\DistributionTools\\TcFirstPageView", model);
}

查看:

Views\DistributionTools\TcFirstPageView.aspx

的Global.asax:

    routes.MapRoute("TrackingChannels", "TrackingChannels/{action}",
        new { controller = "TrackingChannels", action = "InitTcFirstPageView" });

然而,当我冲浪时 http://localhost:85/TrackingChannels/InitTcFirstPageView

我得到了

enter image description here

2 个答案:

答案 0 :(得分:2)

[HttpPost]属性意味着Action只处理POST请求。您需要删除该属性,或使用POST进行测试。

答案 1 :(得分:1)

TrackingChannels是不是控制器的名字呢?你说它是DistributionTools所以你的路线应该是:

routes.MapRoute("TrackingChannels", "DistributionTools/{action}",
        new { controller = "DistributionTools", action = "InitTcFirstPageView" });