MVC4路由参数失败,但查询字符串工作

时间:2015-05-01 01:21:56

标签: c# asp.net-mvc-4 routes umbraco

路线配置:

RouteTable.Routes.MapRoute(
                name: "",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Account", action = "PasswordReset" }
            );

页面控制器:

    [AllowAnonymous]
    [ActionName("PasswordReset")]
    public ActionResult PasswordReset(String id)
    {
        RequestPasswordResetModel model = new RequestPasswordResetModel();

        model.Email = id;
        return View(model);
    }

查看错误位置

@inherits Umbraco.Web.Mvc.UmbracoViewPage<object>
@{
     Layout = null;
}

这是问题所在。

当我去:

/Account/PasswordReset/email%40email.com

我在使用Layout = null

Object Reference not set to an instance时收到错误消息

当我去:

/Account/PasswordReset?id=email%40email.com

一切正常。

此时我完全感到困惑。有什么想法吗?

堆栈追踪:

   at Umbraco.Web.Mvc.UmbracoViewPage`1.WriteLiteral(Object value)
   at ASP._Page_Views_BidNowLayout_cshtml.Execute() in c:\Users\wes.mitchell\Source\Repos\rams-2.0\RAMS-2.0\Presentation.BidNow\Views\BidNowLayout.cshtml:line 3
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.WebPages.WebPageBase.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer)
   at System.Web.WebPages.HelperResult.WriteTo(TextWriter writer)
   at System.Web.WebPages.WebPageBase.Write(HelperResult result)
   at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body)
   at System.Web.WebPages.WebPageBase.PopContext()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)

1 个答案:

答案 0 :(得分:1)

我认为电子邮件编码不正确。尝试使用简单的字符串,当它工作时,您可以使用另一个标识符。在这种情况下,使用GUID是最佳解决方案,因为匿名用户无法通过电子邮件发送电子邮件。