Asp.net mvc 3 查询字符串参数出错

Asp.net mvc 3 查询字符串参数出错,asp.net-mvc-3,routing,Asp.net Mvc 3,Routing,我需要开始处理一个URL,该URL将包含一些电子邮件和GUID。下面的例子中,第一个参数是电子邮件地址,第二个参数是Guid 为此,我修改了我的路线如下 public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "RouteABC", // Route name

我需要开始处理一个URL,该URL将包含一些电子邮件和GUID。下面的例子中,第一个参数是电子邮件地址,第二个参数是Guid

为此,我修改了我的路线如下

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

    routes.MapRoute(
       "RouteABC", // Route name
       "{controller}/{action}/{mail}/{id}", // URL with parameters
       new { controller = "Account", action = "MyActionMethod", mail = string.Empty, id = Guid.Empty } // Parameter defaults
   );

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
    );
}
然后我有我的行动方法如下

 public class AccountController : Controller
    {
        public ActionResult MyActionMethod(string email, Guid id)
        {

            ............
        }
问题是当我进入上面的url时,我得到了以下错误。你知道我做错了什么吗

参数字典包含参数“MyId”的空条目 方法的不可为Null的类型“System.Guid” 'System.Web.Mvc.ActionResult MyActionMethod(System.String, “SmartChartsMVC.Controllers.AccountController”中的“System.Guid”)。一 可选参数必须是引用类型、可为null的类型或 声明为可选参数。参数名称:参数


在格式正确的url中可以有一个问号。它将路径部分与查询字符串分开。因此,您尝试导航到的url无效

更现实的url可以是以下内容:

http://www.myWebSiteurladdress.com/Account/MyActionMethod/me@here.com/222DF915-264E-4034-BF26-22EB1165667C
还要确保路由名称令牌与操作参数匹配。在Global.asax路由定义中,您使用了
{mail}
,而在操作参数中,您使用
email
作为参数名称。确保您的命名约定是一致的

如果你只是想有一个像这样的url:

http://www.myWebSiteurladdress.com/Account/MyActionMethod?MyEmail=me@here.com&MyId=222DF915-264E-4034-BF26-22EB1165667C
然后,您不需要添加任何自定义路由,因为默认路由足以调用以下操作:

public class AccountController : Controller
{
    public ActionResult MyActionMethod(string myEmail, Guid myId)
    {
        ...
    }

    ...
}