Hi, I'm new to using ASP.NET and I'm having trouble collecting the data:
In a view I show several elements in a table and in the last column there is a text box to be filled in by the user. The problem is that I don't know how to collect all the text strings of each of the forms in the Post controller. I would appreciate if someone could help me with this. Thanks in advance.
@if (Model.Habitaciones.Count == 0)
{
<tr><td colsapn="3">No hay habitaciones disponibles</td></tr>
}
else
{
foreach (Habitacion hab in Model.Habitaciones)
{
<tr>
<td>
@Html.DisplayFor(modelItem => hab.NHabitacion)
</td>
<td>
@Html.DisplayFor(modelItem => hab.Tipo.NombreTipo)
</td>
<td>
@Html.DisplayFor(modelItem => hab.Precio)
</td>
<td>
<input type="text" name="Coments" value="Observacion" class="w-50"/>
</td>
</tr>
}
}
One of the options: First in your controller what parameters you want to receive or what parameters you want to send from the view and in your view you must place your labels that you want to send inside a
form action
. Second inActionResult
your controller, set each parameter toname
yourinput
.and in your controller:
This is a brief description of sending data from view to controller, and there are options handling models.