MVC 5 BeginCollectionItem with Partial CRUD

后端 未结 4 1360
夕颜
夕颜 2020-11-30 04:10

I have made changes below to the question, which is still the same but hopefully a lot clearer through the models and in regards to what I want to achieve and where I\'ve co

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 04:52

    You can use (EditorTemplates) to view (ClassB) as following:

    1- Create folder named (EditorTemplates) under the (Views/Home) folder (Assuming your controller name is Home):

    2- Under the created (EditorTemplates) folder, create a view named (ClassB)

    enter image description here

    and add the following template for the (ClassB) view:

    @model Project.Models.ClassB
    @if(Model != null)
    {
    
        
            
                @Html.EditorFor(modelItem => Model.Name)
                
                
            
        
    
    }
    

    and (ClassAView) should be as following:

    @model Project.Models.ClassA
    
    
    
    @Html.EditorFor(m => m.name)
    
    
    @Html.EditorFor(m => m.classB);
    
    
    

    The editor will automatically iterate through the list of objects rendering the view for each of them.

提交回复
热议问题