Hi @Anjali Agarwal
Can I display the input box for emeregencyInfo, emailAddress and phone number in above view. I want to show both the input box for emailAddress and PhoneNumber
In the Create page, you can use the following code to display the EmergencyInfo properties:
@model WebApplication5.Models.EmployeeInfo
@for (var i = 0; i< 2; i++)
{
<hr />
<span>Emergency @i</span>
<div class="form-group">
<label asp-for="@Model.EmergencyInfos.ToList()[i].EmailAddress" class="control-label"></label>
<input asp-for="@Model.EmergencyInfos.ToList()[i].EmailAddress" name="EmergencyInfos[@i].EmailAddress" class="form-control" />
<span asp-validation-for="@Model.EmergencyInfos.ToList()[i].EmailAddress" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="@Model.EmergencyInfos.ToList()[i].PhoneNumber" class="control-label"></label>
<input asp-for="@Model.EmergencyInfos.ToList()[i].PhoneNumber" name="EmergencyInfos[@i].PhoneNumber" class="form-control" />
<span asp-validation-for="@Model.EmergencyInfos.ToList()[i].PhoneNumber" class="text-danger"></span>
</div>
}
The output as below: in this sample, one Employee has two Emergencies, if you want to add more Emergencies, you can change the for-loop
condition.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion