c# - Using a custom editor template for list property -
I've almost done this, but I'm missing a short beta of knowledge This work, this is a quick fix, I know it.
I am putting two ViewModels in one view:
Public class major veem model {public iconging
In a view like this:
& lt; Snip & gt; @HTMLPartial ("_MajorParty") @HTMLPartial ("_minarpal") & lt; Snip & gt;
Whose Looks:
// Mipparartial @ Microsoft.AspNet.Identity @ model ClassPlannerMVC.ViewModels.MajorViewModel @using (Html to use .BeginForm ()) {//@Html.EditorFor(m => M. Major) ?? I'm not able to use it) // "MyPerfectial" has been changed to "Minor" except "Major" and
and then my view / share / editor templates / Major.cshtml and Minor.cshtml
// Major.csthml @model ClassPlannerMVC.Models.Major @ Html.HiddenFor (m => m.ID) & lt; Div class = "form-group" & gt; @ Html.LabelFor (m = & gt; m.Name, new {@class = "col-md-2 control-label"}) & lt; Div class = "col-md-10" & gt; @ Html.EditorFor (m = & gt; m.Name, new {@class = "form-control"}) & lt; / Div & gt; & Lt; / Div & gt; Public Class Major {Receive {Public Int ID}; Set; } Public string name {get; Set; } Public virtual iconging & lt; UserHasMajor & gt; UserHasMajors {receive; Set; }} Public Class Minor {Public Ent ID {get; Set; } Public string name {get; Set; } Public Virtual Icons & lt; UserHasMinor & gt; Get UserHasMinors { Set; }}
Currently, this view does not show my visual model (Major VVM Model, Minor Women Model), which will display editor for Major and Minor respectively. I know that I am passing in some main-major and _parent transparent ideas, and this is the reason I am a @html Can not add editor (X => X), which will display my custom editor template. My code is missing a little too short, is that place you are getting the error?
If necessary, I will upload more code.
You do not see anything passing by for your @partial () methods (iethe model is zero) I recommend that you create another visual model to catch both of them and the main view, like something
public class CombinedViewModel {public MajorViewModel MajorVM {get; Set; } Public MinorViewModel MinorVM {get; Set; }}
In the [HTTGET] method, populate the visual model and pass the main view
public action statement details () {CombinedViewModel model = new CombinedViewModel (); // Set Property Model MajorVM = new MajorGM (); Model.MajorVM.Majors = // Assign to your collection. View return (model); }
then in the main view
@model YourAssembly.CombinedViewModel ... @Html.Partial ("_ MajorPartial", Model.MajorVM) @Html Optional ("_MinorPartial", Model.MinorVM)
Alternatively, there is a visual model with properties public ICollection & lt; Major & gt; Major {receive; Set; }
and public iconging & lt; Minor & gt; Minors {receive; Set; }
(Not sure that you have left some other properties for brevity and therefore you need different visual models)
Comments
Post a Comment