0

I Want Binding List, but I have managed to do it manually, that is to say, so that they are stored in the controller receives the following (Templates[3].Templates[7].Templates[0].Name)

@foreach (var item in Model.Templates)@*--Leve1*@
{
    if (item.Templates.Count() > 0)
    {
        @foreach (var item2 in item.Templates)@*--Leve2*@
        {
            if (item2.Templates.Count() > 0)
            {
                @foreach (var item3 in item2.Templates)@*--Leve3*@
                {
                    if (item3.Templates.Count() > 0)
                    {
                        @foreach (var item4 in item3.Templates)@*--Leve4*@
                        {
                            ...
                        }
                    }
                }
            }
        }
    }
}

there is no way to do it automatically no matter how much level you have, My model is as follows

public class Template
    {

        public int Id { get; set; }

        [Required]
        [MaxLength(150]
        public string Name { get; set; }

        public int? FatherId { get; set; }

        public List<Template> Templates { get; set; }

        public Template ()
        {
            Templates = new List<Template>();
        }
    }

Thanks.

  • Check [this](https://stackoverflow.com/questions/6422895/asp-net-mvc-3-razor-recursive-function) out. – Steve Greene May 01 '19 at 16:03
  • the part of the loops works, but the input is not binding properly. Because when it makes the recursive call every input must have from the beginning of the hierarchies. ex. that is, being Templates [0] level 1, Templates [1] level 2 and Templates [0] level 3, so that the input is binding. thanks. – Elddys Dionisio Carvajal May 03 '19 at 18:07

0 Answers0