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()); }
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.
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
Partial View
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.
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
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);
}
is working on a reply...