路由guid即将出现

时间:2022-12-05 22:58:00

I have an hybrid application which is classic asp.net and MVC both. It is asp.net 4.5 and MVC 4.

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

Problem: From the route, i can get to the action just fine but the guid is always coming up as null. Do you see any thing that i may be missing in my implementation? Problem is with SiteMyHome route.

问题:从路线上,我可以很好地进行动作,但是guid总是会变为空。你看到我在实施中可能遗漏的任何东西吗?问题在于SiteMyHome路线。

Route

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
        );
    }

Action

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

Test /SiteMyHome/9c95eb0-d8fb-4176-9de0-5b99f8b914db/test/matched

When i debug my action, i get the following

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

guid = null
ccode = test
tab = matched

Why is guid getting passed as null here?

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

Now, when i change the action to string guid then i get its value just fine (image attached). I am confused...

现在,当我将动作更改为字符串guid然后我得到它的值就好了(图像附加)。我很迷惑...

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

路由guid即将出现

1 个解决方案

#1


0  

It was a guid issue. The guid that i was testing with is not a valid guid where as d04e9071-0cdf-4aa8-8f34-b316f9f3c466 is resulting in a valid guid.

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

#1


0  

It was a guid issue. The guid that i was testing with is not a valid guid where as d04e9071-0cdf-4aa8-8f34-b316f9f3c466 is resulting in a valid guid.

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