0
我有一个混合的应用程序,这是经典的asp.net和MVC两者。这是asp.net 4.5和MVC 4路由guid为空
问题: 从路线,我可以得到的动作就好了,但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 /测试/匹配
当我调试我的行动,我得到foll欠款
guid = null
ccode = test
tab = matched
为什么guid在这里作为null传递?
现在,当我改变行动字符串指导然后我得到它的价值就好(图片附加)。我很困惑...
public ActionResult SiteMyHome(string guid, string ccode, string tab)
正如你所做的Guid它意味着这个动作参数是可选的可为空场。因此,您可以尝试在相关MapRoute中包含“guid = UrlParameter.Optional”,因为我认为这可能会解决问题。 –
如果我不让它为空,那么我会得到一个错误,因为null传递给动作。错误发生后,我将其更改为可空字段以检查其值。 –