Copied to clipboard

Flag this post as spam?

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


  • Dan Mothersole 22 posts 109 karma points
    Jul 02, 2013 @ 11:39
    Dan Mothersole
    0

    Rendering Model content from a surface controler

    Hi,

    I am testing out Umbraco and am trying to create a profile page that displays the users current information and allows them to update it.

    I am using a surface controler / partal view for this, I can submit data and update the umbraco member but what I am stuggling to get working is displaying the current value held in the umbraco member 'Address' field (custom field).

    Below a snippit of the code I am trying to get working.

    Surface controler

        public class MemberProfileSurfaceController : Umbraco.Web.Mvc.SurfaceController
        {
            // The MemberRegistration Action returns the view. It also instantiates a new, empty model for our view:
            [HttpGet]
            [ActionName("MemberProfile")]
            public ActionResult MemberProfileGet( MemberProfileModel model)
            {
                Member memberEdit = Member.GetCurrentMember();
                model.Address = "Brighton";
                    //memberEdit.getProperty("address").Value.ToString();
                model.Password = memberEdit.Password;
                model.PasswordConfim = memberEdit.Password;
                return PartialView("MemberProfile", new MemberProfileModel());
            }

    Partial View

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<UmbracoMVCAndBootstrap.Models.MemberProfileModel>
    @if (User.Identity.IsAuthenticated)
    { 
        using (Html.BeginUmbracoForm("MemberProfile", "MemberProfileSurface", null, new { @class = "form-horizontal" }))
        {
            @Html.AntiForgeryToken();
        <div class="control-group">
            <label class="control-label" for="Address">Address</label>
            <div class="controls">
                <input type="text" id="Address" name="Address" placeholder="Address" value="@Model.Address" />

    Normaly I would expect Model.Address to render its value to the input value.

    If anyone could help me on this I would be very greatful.

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Jul 02, 2013 @ 12:32
    Andy Butland
    0

    I think it's due to the fact your are passing in an instance of MemberProfileModel into your method as a parameter - it doesn't look like you are using this.  Presumably on this the address property is empty and that's what is getting bound to your model by the MVC model binder. 

    So if you remove that and instead create a new MemberProfileModel() in your method and populate that, it should work as you expect.

    Andy

  • Dan Mothersole 22 posts 109 karma points
    Jul 02, 2013 @ 16:12
    Dan Mothersole
    100

    Hi Andy,

     

    Thanks for the input you put me onto the right track,

    I was passing a new instace of the MemberProfileModel, I changed this to pass through the model instace and it all fell into place.

     

            [HttpGet]

            [ActionName("MemberProfile")]

            public ActionResult MemberProfileGet( MemberProfileModel model)

            {

                Member memberEdit = Member.GetCurrentMember();

     

                model.Address = memberEdit.getProperty("address").Value.ToString();

     

                model.Password = memberEdit.Password;

     

                model.PasswordConfim = memberEdit.Password;

     

                return PartialView("MemberProfile", model);

     

            }

Please Sign in or register to post replies

Write your reply to:

Draft