c# - EditorForTemplate inside a DisplayForTemplate MVC Razor -


I was trying to use HTML display for templates to loop through model data. The template inside my display, I wanted to use an editor, which would display a different set of data, in doing so, I was running on issues where my child model was empty. Upon receiving guidance and guidance from David, I was able to work it down, please find my updated working solution.

Update (Correct Solution)

  Public Segment Targeting Overview {Public Ent dealer ID {get; Set; } Public IR Order Id {get; Set; } Public listing & lt; Targeting array order viewModel & gt; Targeting order order {get; Set; } Public targetingArevaModel () {this.TargetingAreaOrderItems = New list & lt; Targeting arrowheadmetmevalemodel & gt; (); }} Public Segment Targeting Order Order ViewModel {Public Entit order item {get; Set; } Public Input PackagesMediaType ID {Received; Set; } Public string PackageMediaTypeHeader {get; Set; } Public string MediaTypeDesc {get; Set; } Public string targeting AdditonalInfo {get; Set; } Public listing & lt; TargetingAreaItemViewModel & gt; Targeting array {get; Set; } Public Targeting Order Order ViewModel () {this.TargetingAreaItems = New List & lt; TargetingAreaItemViewModel & gt; (); }} Public Category TargetingEreateMoviewModel {Public Entitlement Item {Receipt} Set; } Public Entry PackageMedia TargetingFildID {Received; Set; } Public String TargetingAreaFieldTitle {get; Set; } Public string TargetingValue {get; Set; } Received Public Bull iNated { Set; } Public Child ITEEre {get; Set; } Public string comment {get; Set; }}   

Parent View @ Model Model. TargetingEreviewModel @ {ApplicationContext.Current.PageTitle = "Targeting Information"; Layout = "~ / view / share / main layout.cshtml"; } @using (Html.BeginForm ("OrderItemTargetingInfo", "Home", FormMethod.Post, New {@class = "form-horizontal"}) {@ Html.DisplayFor (m = & gt; m.TargetingAreaOrderItems) & lt ; Div class = "call-sm-12" & gt; & Lt; Div class = "pull-right" & gt; & Lt; Input id = "submit" type = "submit" value = "submit" class = "btn btn-primary" /> & Lt; / Div & gt; & Lt; / Div & gt; }

View the template for display

  @ Model Model. TargetingAreorder ItemView Model & lt; Div class = "row" & gt; & Lt; Div class = "col-sm-12" & gt; & Lt; Div class = "colon-sm-12btn-primary" style = "margin-bottom: 10px; margin-top: 10px;" & Gt; @html Labels (Model MediaType Disk, New {@style = "font-weight: bold; padding-top: 10px; font-size: 18px;"}) @html.headedfor (m => m oder etamid) And LT; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "row" & gt; & Lt; Div class = "col-md-12" & gt; @html Ro (model package media type header) & lt; / Div & gt; & Lt; / Div & gt; & Lt; Br / & gt; & Lt; Div class = "row" & gt; & Lt; Div class = "col-sm-12" & gt; @ Html.EditorFor (m = & gt; m.TargetingAreaItems) & lt; / Div & gt; & Lt; / Div & gt; & Lt; Br / & gt; & Lt; Div class = "row" & gt; & Lt; Div class = "col-md-12" & gt; & Lt; Div class = "form-group" & gt; @html Label ("Additional information:", New {@class = "control-label col-md-2"}) & lt; Div class = "col-md-6" & gt; @ Html.TextAreaFor (m = & gt; m.TargetingAdditonalInfo, new {@class = "form-control"}) & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;   

Now, I am capable of displaying data, receiving data of my model on the post. Works great !!

In your parents' thoughts, you only designate targeting order orders but children Instead, you should go to the entire model instead of the targeting observation module instead:

  @ html.DisplayFor (m = & gt; m)  < / Pre>  

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -