Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Marcio Goularte 343 posts 1142 karma points
    Aug 24, 2019 @ 02:13
    Marcio Goularte
    0

    Cannot bind source type System.String to model type Umbraco.Core.Models.PublishedContent.IPublishedContent

    Strange error with Html.Action. I always implemented it using SurfaceController and Child Actions.

    But now with V8 when using two Html.Action in the same template I have this error:  

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        Layout = "_Layout.cshtml";
    }
    
    <section id="content">
        <div class="content-wrap">
            <div class="container clearfix">
                <div class="col_one_third nobottommargin">
                    <div class="well well-lg nobottommargin">
                        @Html.Action("LoginForm", "Account")                   
                    </div>
                </div>
                <div class="col_two_third col_last nobottommargin">
                    <h3>Ainda não possui um cadastro?</h3>
                    <p>É gratuito e fácil!</p>
                    @Html.Action("Register", "Account")              
                </div>
            </div>
        </div>
    </section>
    

    //SurfaceController

    [ChildActionOnly]
            public ActionResult LoginForm()
            {
                return PartialView(PartialViews.LoginForm, new LoginModel());
            }
    
            [ChildActionOnly]
            public ActionResult Register()
            {
                return PartialView(PartialViews.RegisterForm, new RegisterModel());
            }
    

    So when it loads the first time it works. The page loads normally. But when I post from the login form and return to CurrentUmbracoPage for not finding the user, this error happens.

            [HttpPost]            
            [ValidateAntiForgeryToken]   
            public async Task<ActionResult> SignIn(LoginModel loginModel, string returnUrl)
            {
                if (!ModelState.IsValid)
                {
                    return CurrentUmbracoPage();
                }
    
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, change to shouldLockout: true
                var result = await SignInManager.PasswordSignInAsync(loginModel.Email, loginModel.Password, loginModel.RememberMe, shouldLockout: false);
                switch (result)
                {
                    case SignInStatus.Success:
                        try
                        {
                            //Set is logged and register history
                            _memberIdentityService.RegisterLogin(loginModel.Email);
                            return RedirectToLocal(returnUrl);
                        }
                        catch (Exception ex)
                        {
                            var msg = "Tentativa de login inválida";
                            _logger.Error<AccountController>(ex, msg);
                            ModelState.AddModelError("", msg);
                            return CurrentUmbracoPage();
                        }
                    case SignInStatus.LockedOut:
                        ModelState.AddModelError("Lockout", "Lockout");
                        return RedirectPermanent(Routes.Lockout);
                    case SignInStatus.RequiresVerification:
                        return RedirectPermanent(Routes.SendCode + $"?ReturnUrl={returnUrl}&RememberMe={loginModel.RememberMe}");                    
                    case SignInStatus.Failure:
                    default:
                        //RETURN HERE
                        ModelState.AddModelError("Email", "nome de usuário ou senha inválidos");
                        return CurrentUmbracoPage();
                }
            }
    

    But if you use only one Html.Action, using one Html.Partial, the error does not happen. This code below does not occur this error

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        Layout = "_Layout.cshtml";
    }
    
        <section id="content">
            <div class="content-wrap">
                <div class="container clearfix">
                    <div class="col_one_third nobottommargin">
                        <div class="well well-lg nobottommargin">
                            @Html.Action("LoginForm", "Account")                   
                        </div>
                    </div>
                    <div class="col_two_third col_last nobottommargin">
                        <h3>Ainda não possui um cadastro?</h3>
                        <p>É gratuito e fácil!</p>
                        @Html.Partial(Lania.MemberIdentity.Constants.PartialViews.RegisterForm, new RegisterModel())              
                    </div>
                </div>
            </div>
        </section>
    

    This code is something I carried from a version using V7. It always worked. There were few changes.

    StackTrace:

       em System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
       em System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage)
       em System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm)
       em System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm)
       em System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter)
       em System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues)
       em System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName)
       em ASP._Page_Views_login_cshtml.Execute() na D:\projetos\LaniaV4\src\Lania\Lania.Ead.UI\Views\login.cshtml:linha 17
       em System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       em System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
       em System.Web.WebPages.StartPage.RunPage()
       em System.Web.WebPages.StartPage.ExecutePageHierarchy()
       em System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
       em System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
       em System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
       em Umbraco.Web.Mvc.ProfilingView.Render(ViewContext viewContext, TextWriter writer) na d:\a\1\s\src\Umbraco.Web\Mvc\ProfilingView.cs:linha 25
       em System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
       em System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
       em System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
       em System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
    

    I want to know if anyone has been through this, or if they have any solution.

Please Sign in or register to post replies

Write your reply to:

Draft