Copied to clipboard

Flag this post as spam?

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


  • Nicky Christensen 76 posts 166 karma points
    Feb 06, 2014 @ 12:44
    Nicky Christensen
    0

    Error message from Umbraco Field in SurfaceController

    I have a field in Umbraco, where the user can input a error text - How do i use that in a controller?
    Look at the line: ModelState.AddModelError("", "I WANT THE MESSAGE FROM UMBRACO FIELD HERE");

    if (!ModelState.IsValid)
                {
                    return CurrentUmbracoPage();
                }
    
                if (Membership.ValidateUser(model.Username, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.Username, false);
                    return Redirect("/logged-in-page/");
                }
                else
                {
                    //Write an error
                    ModelState.AddModelError("", "I WANT THE MESSAGE FROM UMBRACO FIELD HERE");
                    return CurrentUmbracoPage();
                }
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Feb 06, 2014 @ 22:25
    Jeavon Leopold
    0

    Hi Nicky,

    Is the field on the same node as the CurrentUmbracoPage or some other node?

    Jeavon

  • Nicky Christensen 76 posts 166 karma points
    Feb 07, 2014 @ 08:59
    Nicky Christensen
    0

    The field is on the same node

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Feb 07, 2014 @ 10:37
    Jeavon Leopold
    0

    Ok then:

    using Umbraco.Web;
    
    if (!ModelState.IsValid)
                {
                    return CurrentUmbracoPage();
                }
    
                if (Membership.ValidateUser(model.Username, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.Username, false);
                    return Redirect("/logged-in-page/");
                }
                else
                {
                    //Write an error
                                    var myProperty = CurrentPage.HasProperty("myProperty") && CurrentPage.HasValue("myProperty")
                                     ? CurrentPage.GetPropertyValue<string>("myProperty")
                                     : "Default message";
    
                    ModelState.AddModelError("", myProperty);
                    return CurrentUmbracoPage();
                }
    
Please Sign in or register to post replies

Write your reply to:

Draft