I do not know how to properly display input in the View.

I make a form for adding managers to the company.

<div class="one field"> <div class="field"> <h3 class="ui dividing header"> Менеджер </h3> </div> </div> foreach (var manager in Model.Supplier.Managers) { <div class="two fields"> <div class="field"> <label>ФИО</label> @Html.TextBoxFor(m => manager.Name) </div> <div class="field"> </div> </div> <div class="two fields"> <div class="field"> <label>Телефон</label> @foreach (var phone in manager.Phones) { @Html.TextBoxFor(m => phone.PhoneNumber) } </div> <div class="field"> <label>Почта</label> @foreach (var email in manager.Emails) { @Html.TextBoxFor(m => email.Contact_Email) } </div> </div> } 

So, what is logical if I don’t have it in the data model, I’m not drawing this textbox at all. And I need to draw. According to the idea this can be done using IF / but the design will be cumbersome, I would like to know if there is any elegant way to solve this problem?

  • Templates - free_ze
  • If you suddenly about cycles for phone numbers and mail addresses, then attend to this issue at the model level, for example, and in the case of creating a new object, add one empty phone and email object to the collections. This will allow you to always show at least one entry. Other options are to add if to check if list is empty, etc. But still, you probably want to add additional addresses and phone numbers, so you will probably have an "Add phone" button, which with JS will draw input fields. - teran
  • Yes, and in general, it is somewhat strange that you seem to be adding a new manager, and in the code you have the current records of the managers (that is, the cycle). - teran

0