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.

2
  • Check this out. Commented May 1, 2019 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. <input name="Templates [0] .Templates [1] .Templates [0] .Name" type="Text"/> that is, being Templates [0] level 1, Templates [1] level 2 and Templates [0] level 3, so that the input is binding. thanks. Commented May 3, 2019 at 18:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.