路由guid即将出现

时间:2014-03-26 23:39:25

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

我有一个混合应用程序,它是经典的asp.net和MVC。它是asp.net 4.5和MVC 4。

问题: 从路线上,我可以很好地完成动作,但是guid总是会变为空。您是否看到我在实施中可能遗漏的任何内容?问题在于SiteMyHome路线。

路线

public static void RegisterRoutes(RouteCollection routes)
    {

        routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
        //Ignore calls to httphandlers
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            RouteConstants.SiteMyHome,
            RouteConstants.SiteMyHome + "/{guid}/{ccode}/{tab}",
            new { controller = ControllerNames.SiteRouter, action = ActionNames.SiteMyHome, ccode = UrlParameter.Optional, tab = UrlParameter.Optional }
        );


        //Set the default route
        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );
    }

动作

public ActionResult SiteMyHome(Guid? guid, string ccode, string tab)
    {
        return null;
    }

测试 / SiteMyHome / 9c95eb0-d8fb-4176-9de0-5b99f8b914db /测试/匹配

当我调试我的动作时,我得到以下

guid = null
ccode = test
tab = matched

为什么guid在这里被传递为null?

现在,当我将操作更改为字符串guid 时,我得到它的值就好了(附图像)。我很困惑......

public ActionResult SiteMyHome(string guid, string ccode, string tab)

enter image description here

1 个答案:

答案 0 :(得分:0)

这是一个guid问题。我测试的guid不是有效的guid,因为d04e9071-0cdf-4aa8-8f34-b316f9f3c466导致有效的guid。

相关问题