c# - Populate View selected record ViewModel -


i trying use viewmodel way validates.

my viewmodel:

public class ccvm {     [required(errormessage = "please enter name")]     public string cardholdername { get; set; }     [required(errormessage = "please enter credit card number")]     public string cardnumber { get; set; }     [required(errormessage = "please enter expiration date mmyy")]     [stringlength(4, errormessage = "expiration date format mmyy", minimumlength = 4)]     public string cardexpirtydate { get; set; }      public wholesale wholesale { get; set; } } 

how can pass selected person in wholesaler , card info view?

my controller:

public actionresult pay() {     if (session["wid"] == null)     {         return redirecttoaction("index");     }     viewbag.step = 2;     if (session["wid"] == null)     {         return new httpstatuscoderesult(httpstatuscode.badrequest);     }     //wholesale wholesale = db.wholesales.find(session["wid"]);     int wid=convert.toint32(session["wid"]);     ccvm ccvm = new ccvm();     var dude = d in db.wholesales                d.id==wid                select d;     ccvm.wholesale = (dude.tolist());     if (ccvm == null)     {         return httpnotfound();     }     return view(ccvm); } 

view has fields wholesaler table want use vm validate , controller update. has card info need vm validate , pass controller processing.

@html.editorfor(model => model.firstname) @html.validationmessagefor(model => model.firstname, "", new { htmlattributes = new { @placeholder = "first name please", @class = "text-danger" } })  <input type="text" name="cardexpirtydate" style="width:40px" />mmyy <br />@html.validationmessagefor(model => model.cardexpirtydate) 

depending on project, can use model-view-viewmodel pattern (https://msdn.microsoft.com/en-us/library/ff798384.aspx). here article on topic using automapper: https://lostechies.com/jimmybogard/2009/06/30/how-we-do-mvc-view-models

if want see arguments counter side, here article debates points: http://www.uglybugger.org/software/post/friends_dont_let_friends_use_automapper

personally, i've found viewmodel pattern automapper work forms on data type projects.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -