Copied to clipboard

Flag this post as spam?

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


  • Ilya 18 posts 53 karma points
    Aug 19, 2014 @ 19:47
    Ilya
    0

    Building simple profile editor based on ProfileModel (Umbraco v. 6)

    Hi everyone.

    I'm trying to build a simple front end profile editor.

    I've created a new Member type with couple of custom properties, and used a standard "Edit Profile" Razor macro.

    That works great - I mean, now it's possible to build a quick property editor using piece of code like this:

    @{
    var profileModel = Members.GetCurrentMemberProfileModel();
    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();
    Html.RequiresJs("/umbraco_client/ui/jquery.js");
    Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
    Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
    var success = TempData["ProfileUpdateSuccess"] != null;
    }
    using (Html.BeginUmbracoForm("HandleUpdateProfile"))
    {

    Edit profile


    @Html.ValidationSummary("profileModel", true)

    @for (var i = 0; i < profileModel.MemberProperties.Count; i++)
    {

    @Html.LabelFor(m => profileModel.MemberProperties[i].Value, profileModel.MemberProperties[i].Name)
       @Html.EditorFor(m => profileModel.MemberProperties[i].Value)
    @Html.HiddenFor(m => profileModel.MemberProperties[i].Alias)

    }

    }
    }

     

    The problem is that all editors created by @Html.EditorFor helper are simple textboxes. I guess that's because  MemberProperties[i].Value is always a string.

    My question is - how can I create an editor for bool (true/false) properties (checkbox), date properties(datepicker or something like this), numeric and so on? In  "Edit Profile" snippet there is some info in comments about creating a custom editor and putting in in the ~/Views/Shared/EditorTemplates folder. I've tried this way, but I don't understand how to convert the string values to other types keeping those values binded to ProfileModel (and saved in umbraco with all simple textbox properties).

    Can anyone suggest the solution? Any examples, code snippets and guides would be very appreciated (for example, if there are custom editortemplates available) . Thanks!

    P.S. I'm new to umbraco v.6 and MVC (previously worked with v.4.9), so please feel free to point me on any mistakes or bad practicies (if there are any).

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Dec 29, 2014 @ 16:30
Please Sign in or register to post replies

Write your reply to:

Draft