简体   繁体   中英

How to Fill List dynamically with Partial Views Asp.net mvc

In my web application User can Add New Tabs

TabModel 

{
public string TabName {get; set;}
public List<SubTabModel> Subs {get; set;}
}

Each Tab can contain List of SubTabs

SubTabModel
{
public string SubTabName {get ; set;}
}

How to perform usabilty of Adding Sub Tabs, and get fully functionality of Requirement attribute and Posting this Tab model with her SubTabs and proceed?

SubTabModel
{
public string SubTabName {get ; set;}
public T RelatedModel {get ; set;}
}

You need to use generic related mvc model with you can apply Validations. You can do like that.

I hope the following will help you

Partial View

@model List<TabModel>

@{
    <ul>
        @foreach (var item in Model)
        {
            <li>
                <a>@item.TabName</a>
                @if (item.Subs != null)
                {
                    <ul>
                        @foreach (var subItem in item.Subs)
                        {
                            <li>
                                <a>@subItem.SubTabName</a>
                            </li>
                        }
                    </ul>
                }
            </li>
        }
    </ul>
}

Controller

   return PartialView("PartialViewName", TabModel);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM