Thursday, 15 April 2010

c# - EditorForTemplate inside a DisplayForTemplate MVC Razor -



c# - EditorForTemplate inside a DisplayForTemplate MVC Razor -

i trying utilize html display template looping through model data. within display template, wanted utilize editorfor template display different set of data, in doing so, running issues kid model empty. upon playing around , getting guidance david, able create work. below, please find updated working solution.

update (correct solution)

public class targetingareaviewmodel { public int dealerid { get; set; } public int orderid { get; set; } public list<targetingareaorderitemviewmodel> targetingareaorderitems { get; set; } public targetingareaviewmodel() { this.targetingareaorderitems = new list<targetingareaorderitemviewmodel>(); } } public class targetingareaorderitemviewmodel { public int orderitemid { get; set; } public int packagemediatypeid { get; set; } public string packagemediatypeheader { get; set; } public string mediatypedesc { get; set; } public string targetingadditonalinfo { get; set; } public list<targetingareaitemviewmodel> targetingareaitems { get; set; } public targetingareaorderitemviewmodel() { this.targetingareaitems = new list<targetingareaitemviewmodel>(); } } public class targetingareaitemviewmodel { public int orderitemid { get; set; } public int packagemediatargetingfieldid { get; set; } public string targetingareafieldtitle { get; set; } public string targetingvalue { get; set; } public bool isenabled { get; set; } public bool isrequired { get; set; } public string comment { get; set; } }

parent view

@model models.targetingareaviewmodel @{ applicationcontext.current.pagetitle = "targeting info"; layout = "~/views/shared/mainlayout.cshtml"; } @using (html.beginform("orderitemtargetinginfo", "home", formmethod.post, new { @class = "form-horizontal" })) { @html.displayfor(m => m.targetingareaorderitems) <div class="col-sm-12"> <div class="pull-right"> <input id="submit" type="submit" value="submit" class="btn btn-primary" /> </div> </div> }

displayfor template view

@model models.targetingareaorderitemviewmodel <div class="row"> <div class="col-sm-12"> <div class="col-sm-12 btn-primary" style="margin-bottom: 10px; margin-top: 10px;"> @html.label(model.mediatypedesc, new { @style = "font-weight: bold; padding-top: 10px; font-size: 18px;" }) @html.hiddenfor(m => m.orderitemid) </div> </div> </div> <div class="row"> <div class="col-md-12"> @html.raw(model.packagemediatypeheader) </div> </div> <br /> <div class="row"> <div class="col-sm-12"> @html.editorfor(m => m.targetingareaitems) </div> </div> <br /> <div class="row"> <div class="col-md-12"> <div class="form-group"> @html.label("additional info:", new { @class = "control-label col-md-2" }) <div class="col-md-6"> @html.textareafor(m => m.targetingadditonalinfo, new { @class = "form-control" }) </div> </div> </div> </div>

now, able display data, info out of model on post. works great!!

in parent views passing in targetingareaorderitems of model kid view expecting targetingareaviewmodel. instead should pass in entire model:

@html.displayfor(m => m)

c# asp.net-mvc

No comments:

Post a Comment