asp.net mvc - MVC4 Registering a user with extra details -
i beginer in mvc. want that, user wil have location. want keep locations in seprate table.
the models came are:
location model:
public class location { [key] [databasegeneratedattribute(databasegeneratedoption.identity)] public int locationid { get; set; } public string address { get; set; } public string city { get; set; } public string state { get; set; } public string postalcode { get; set; } }
userprofile model:
public class userprofile { [key] [databasegeneratedattribute(databasegeneratedoption.identity)] public int userid { get; set; } public string username { get; set; } public string name { get; set; } public virtual location location { get; set; } }
register model:
public class registermodel { //attributes username , password , confirmpassword public string name { get; set; } public virtual location location { get; set; } }
register controller :
public actionresult register(registermodel model) { if (modelstate.isvalid) { // attempt register user try { websecurity.createuserandaccount(model.username, model.password, propertyvalues: new { location = new location () , name = model.name }); websecurity.login(model.username, model.password); return redirecttoaction("index", "home"); } catch (membershipcreateuserexception e) { modelstate.addmodelerror("", errorcodetostring(e.statuscode)); } } // if got far, failed, redisplay form return view(model); }
now when try register,
error : no mapping exists object type hirecar2.models.location known managed provider native type.
i have been trying on since noon. can know wrong in above code.
Comments
Post a Comment