Copied to clipboard

Flag this post as spam?

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


  • Alexander Carpenter 19 posts 141 karma points
    Aug 11, 2018 @ 05:07
    Alexander Carpenter
    0

    Placeholder as current member value

    I am trying to make it possible for a member to edit their current profiles.

    Is there a way to make the placeholder output what the current value is?

    @Html.TextBoxFor(model => model.FirstName, new { placeholder = "First Name" })
    

    works fine but I can't find a variation of

    @Html.TextBoxFor(model => model.FirstName, new { placeholder = "@member.GetValue("firstName")" })
    

    that will work because I don't know how to get the logged in member into the partial view for the html editors.

  • Marcel van Helmont 68 posts 259 karma points c-trib
    Aug 11, 2018 @ 09:18
    Marcel van Helmont
    0

    Have a look at the documentation https://our.umbraco.com/Documentation/Reference/Templating/Mvc/examples

    Last Example is to get member values, also will the syntax look like this.

    @Html.TextBoxFor(model => model.FirstName, new { placeholder = member.GetValue("firstName”) })

  • Alexander Carpenter 19 posts 141 karma points
    Aug 11, 2018 @ 17:35
    Alexander Carpenter
    0

    Their example would work in other partial views, but it does not work within the form partial view.

    var username = System.Web.Security.Membership.GetUser().UserName;
    var member = ApplicationContext.Services.MemberService.GetByUsername(username);
    

    I have been using that, which is effectively the same thing, but regardless of what dependencies I include neither of those will render within the form partial view. This one doesn't allow ApplicationContext and their version:

        @if(Members.IsLoggedIn()){
       var profile = Members.GetCurrentMemberProfileModel();
       var umbracomember = Members.GetByUsername(profile.UserName);
    
        <h1>@umbracomember.Name</h1>
        <p>@umbracomember.GetPropertyValue<string>("bio")</p>
    }
    

    doesn't allow Members. Both will work in my controllers or other partial views, but not the form partial view.

  • Marcel van Helmont 68 posts 259 karma points c-trib
    Aug 11, 2018 @ 19:53
    Marcel van Helmont
    0

    Don’t know what you mean with form Partial view. Where and how do you call the partial view?

  • Alexander Carpenter 19 posts 141 karma points
    Aug 11, 2018 @ 19:57
    Alexander Carpenter
    0
    @using BoldLogistics.Controllers
    @model BoldLogistics.Models.GeneralApplicationModel
    
    @using (Html.BeginUmbracoForm<GeneralApplicationController>("GeneralApplication"))
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)
    
        <p>First Name</p>
        @Html.TextBoxFor(model => model.FirstName, new { placeholder = "First Name" })
        @Html.ValidationMessageFor(model => model.FirstName)
    
        @Html.LabelFor(model => model.LastName)
        @Html.EditorFor(model => model.LastName)
        @Html.ValidationMessageFor(model => model.LastName)
    
        <button class="button" id="contact-submit" type="submit"> Update</button>
    
    }
    

    That is what I mean, the partial view for the html form.

     @{ Html.RenderPartial("~/Views/Partials/GeneralApplicationPartial.cshtml", new GeneralApplicationModel());}
    

    Is how I call the partial view from the template.

    Sorry if my terminology of any of this is off. I am new both to Umbraco and to MVC.

  • Marcel van Helmont 68 posts 259 karma points c-trib
    Aug 11, 2018 @ 21:14
    Marcel van Helmont
    0

    Add this on top of the partial view and try if it works

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    This will give you acces to the properties you need

    Refrence https://our.umbraco.com/documentation/reference/templating/mvc/partial-views

  • Alexander Carpenter 19 posts 141 karma points
    Aug 11, 2018 @ 21:25
    Alexander Carpenter
    0

    enter image description here

    That is where I am running into the problem, the form partial (or mvc partial? idk what to call it) isn't the same as a regular one, it won't allow that and still perform its intended function. There must be a way to pass the member value into the function, but I can't figure out how to do that.

  • Marcel van Helmont 68 posts 259 karma points c-trib
    Aug 11, 2018 @ 21:33
    Marcel van Helmont
    0

    Remove the @model statement and try

    @inherits Umbraco.Web.Mvc.UmbracoViewPage

    UmbracoViewPage have its own Model property so the rest can be the same.

    The only thing i dont know i UmbracoViewPage need an RenderModel

  • Alexander Carpenter 19 posts 141 karma points
    Aug 11, 2018 @ 21:41
    Alexander Carpenter
    0

    That specific model is required for the form to work. That is what contains the property values/types. Without that everything breaks because there aren't definitions for the form variables.

    namespace BoldLogistics.Models
    {
        public class GeneralApplicationModel
        {
            [Required(ErrorMessage ="First Name is Required")]
            public string FirstName { get; set; }
    
            [Required(ErrorMessage ="Last Name is Required")]
            public string LastName { get; set; }        
        }
    }
    

    Without the model the error is: enter image description here

    For every field

  • Alexander Carpenter 19 posts 141 karma points
    Aug 11, 2018 @ 22:35
    Alexander Carpenter
    101

    Figured it out. Found a way to get the user without dependencies, or at least from already included dependencies. Why this one works and the others don't I am not entirely sure, but it does.

    var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(Umbraco.Web.UmbracoContext.Current);
    var Username = memberShipHelper.GetCurrentMember();
    

    Then I can do either:

    @Html.TextBoxFor(model => model.FirstName, new { placeholder = Username.GetPropertyValue("firstName") })
    

    For a placeholder, or take it a step further and actually preset the value:

    @Html.TextBoxFor(model => model.FirstName, new { @Value = Username.GetPropertyValue("firstName") })
    

    This works so I am marking it as solved, but if anyone knows why this version works and none of the others do I would be interested to know. I hate programming through guess and check and I don't understand the differences between what is allowed and what isn't in various positions.

  • Marcel van Helmont 68 posts 259 karma points c-trib
    Aug 12, 2018 @ 17:08
    Marcel van Helmont
    0

    Don’t know how you setup your model. Or maybe is only a empty model but i think you are trying to create a member profile edit view..

    Maybe you can find inspiration how it’s done in our.

    https://github.com/umbraco/OurUmbraco/tree/master/OurUmbraco.Site/Views/Partials/Members

Please Sign in or register to post replies

Write your reply to:

Draft