using System.ComponentModel.DataAnnotations;
using System.Web;
namespace BootstrappedDNDCC.Models
{
public class RegisterModel
{
[Required]
public string Name { get; set; }
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
public string Password { get; set; }
public string Biography { get; set; }
public HttpPostedFileBase Avatar { get; set; }
}
}
And the controller (RegisterMemberSurfaceController.cs):
using System.Web.Mvc;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
namespace BootstrappedDNDCC.Controllers
{
public class RegisterMemberSurfaceController : SurfaceController
{
// GET: RegisterMemberSurface
public ActionResult Register(RegisterModel model)
{
if (!ModelState.IsValid)
return CurrentUmbracoPage();
var memberService = Services.MemberService;
if (memberService.GetByEmail(model.Email) != null)
{
ModelState.AddModelError("", "A member with that email already exists");
return CurrentUmbracoPage();
}
var member = memberService.CreateMember(model.Email, model.Email, model.Name, "registeredMember");
member.SetValue("userProfileBio", model.Biography);
member.SetValue("userProfileAvatar", model.Avatar);
memberService.SavePassword(member, model.Password);
Members.Login(model.Email, model.Password);
memberService.Save(member);
return Redirect("/");
}
}
}
The Email, Password and Name values are recognized by the controller, but the Biography and the Avatar properties arent.
I'm getting the following error:
Error CS1061 'RegisterModel' does not contain a definition for 'Biography' and no extension method 'Biography' accepting a first argument of type 'RegisterModel' could be found (are you missing a using directive or an assembly reference?) BootstrappedDNDCC E:\Projects\Sites\BootstrappedDNDCC\BootstrappedDNDCC\Controllers\RegisterMemberSurfaceController.cs 25 Active
I followed the tutorials strictly, since I'm all green to working with the APIs and controller/models for that matter.
In my view, the values are recognized, so the problem lies only within the controller as far as I can tell.
Am I supposed to do something special when I start up VS? I tried rebuilding the solution and project, but still no connection, so to say.
Hope you guys can help me in the right direction, cus I feel a bit lost at the moment :)
Umbraco defines it's own RegisterModel in Umbraco.Web.Models. Your code is using this model instead of your custom one. Update your Register method signature as follows and it should work:
public ActionResult Register(BootstrappedDNDCC.Models.RegisterModel model)
Custom member properties not defined in controller
Hi guys
I'm watching the Umbraco.tv Member section, and I've run into some trouble.
I've added a few extra custom member properties, as done in the tutorial, but my model simply don't recognize the custom values.
My code is as follow:
The view (MemberRegister.cshtml):
The model (RegisterMemberViewModel.cs):
And the controller (RegisterMemberSurfaceController.cs):
The Email, Password and Name values are recognized by the controller, but the Biography and the Avatar properties arent.
I'm getting the following error:
Error CS1061 'RegisterModel' does not contain a definition for 'Biography' and no extension method 'Biography' accepting a first argument of type 'RegisterModel' could be found (are you missing a using directive or an assembly reference?) BootstrappedDNDCC E:\Projects\Sites\BootstrappedDNDCC\BootstrappedDNDCC\Controllers\RegisterMemberSurfaceController.cs 25 Active
I followed the tutorials strictly, since I'm all green to working with the APIs and controller/models for that matter.
In my view, the values are recognized, so the problem lies only within the controller as far as I can tell.
Am I supposed to do something special when I start up VS? I tried rebuilding the solution and project, but still no connection, so to say.
Hope you guys can help me in the right direction, cus I feel a bit lost at the moment :)
Thank you in advance
Best
Henrik
Hi Henrik,
Umbraco defines it's own
RegisterModelinUmbraco.Web.Models. Your code is using this model instead of your custom one. Update yourRegistermethod signature as follows and it should work:Steven
James
You are my savior!
Stared into the code for so long and I simply couldn't figure out where I went wrong, since some of the props were defined.
Thank you very much for the quick reply.
Have a great evening :)
Best
Henrik
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.