A quick question:
So, I am developing a small MVC/C# application and I am using ViewModel to pass data to my view. The ViewModel is actually a combination of 3 Models.
My Models:
public class Sourcing_ProfileSourcingAreas
{
public string Area { get; set; }
public string Details { get; set; }
}
public class DefCountry
{
public string CountryName { get; set; }
public string CountryCode { get; set; }
}
My ViewModel:
public class SourcingIndex
{
public List<DefCountry> CountryLst { get; set; }
public List<Sourcing_ProfileSourcingAreas> AreaLst { get; set; }
}
On my view, I put this line at the top @model SourcingIndex
to declare that I will be using this ViewModel
I also was easily able to specify which model I want to display by using foreach
loop, for example:
@foreach (Sourcing_ProfileSourcingAreas area in Model.AreaLst)
{
<tr>
<td>@area.Area</td>
<td>@area.Details</td>
</tr>
}
And
@foreach (DefCountry ctry in Model.CountryLst)
{
<option>@ctry.CountryName</option>
}
However, I am not able to create @Html.TextBox
and assign it to a specific property in a model!
If possible, I want it to be somthing like this: @Html.TextBoxFor(model => model.AreaLst.Area)
Thank you