c# - Pass a user to a ViewModel -


ok, little stuck here.

viewmodel

public class userprofileedit {     public virtual applicationuser applicationuser { get; set; }      [required]                 public string firstname { get; set; }      public string twitterhandle{ get; set; }      [required]     [display(name = "email")]     [datatype(datatype.emailaddress)]     public string email { get; set; }      // etc etc } 

controller

public actionresult yourprofile() {     string username = user.identity.name;                 applicationuser user = db.users.firstordefault(u => u.username.equals(username));      // construct viewmodel     userprofileedit model = new userprofileedit();                model.applicationuser = user;       return view(model);  } 

and on view have @model mysite.models.userprofileedit @ top.

how can pass user viewmodel? know can line line

model.email = user.email; 

for example, should simpler?

you can line line, or can use automapper. give try http://automapper.org/

this useful specially when have same kind of object mappings repeated in code.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -