MVC路由配置

时间:2016-09-26 00:55:37

标签: asp.net-mvc c#-4.0 asp.net-mvc-routing

我的HomeController中有以下内容:

public ActionResult Share(string id)
{
    Debate debate;
    try
    {
        debate = Db.Debates.Single(deb => deb.ShareText.Equals(id));
    }
    catch (Exception)
    {
        return RedirectToAction("Index");
    }
    return View(debate);
}

这允许我这样调用网址:

http://localhost:50499/Home/Share/SomeTextHere

我在routeconfig文件中以这种方式配置了路由:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Share",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Share", id = UrlParameter.Optional }
    );

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}

我希望能够以这种方式调用URL:

http://localhost:50499/Debate/SomeTextHere

我一直在努力,没有运气。实现它的最佳方法是什么?

1 个答案:

答案 0 :(得分:2)

如@StephenMuecke的评论所述,您需要更改路线,使其不那么普遍。

Share

http://localhost:50499/Debate/SomeTextHere路由现在允许>>> data2 = [[1, np.nan], [2, -17]] >>> f2 = pd.DataFrame(data2) >>> f2 0 1 0 1 NaN 1 2 -17.0 >>> f2.values[1, 1] = -99.0 >>> f2 0 1 0 1 NaN 1 2 -17.0 >>> type(f2.values[0, 0]), type(f2.values[1, 0]) (<class 'numpy.float64'>, <class 'numpy.float64'>) 路由到相应的控制器操作。