Wesley
Wesley

Reputation: 5621

MVC4 Route Parameter Fails, but Query String works

Route Config:

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

Page Controller:

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

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

View Error Location

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

Here is the problem.

When I go to:

/Account/PasswordReset/email%40email.com

I get an error on Layout = null with Object Reference not set to an instance

When I go to:

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

Everything works fine.

I am completely confused at this point. Any ideas?

Stack Trace:

   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)

Upvotes: 0

Views: 98

Answers (1)

Miroslav Holec
Miroslav Holec

Reputation: 3217

I suppose that email is not encoded correctly. Try to do it with simple string and when it will works, you can use another identifier. In this case is the best solution using the GUID, because email can not by revealed by anonymous user.

Upvotes: 1

Related Questions