Using Visual Studio 2017, .Net Core 2.1, Web Site
With this model
public class TestObj{ [DataType(DataType.Text)] public string str1 { get; set; } [DataType(DataType.Text)] public int int1 { get; set; } public List<TestObj> TestList { get; set; } public TestObj() { } public TestObj(string i_str, int i_int) { this.str1 = i_str; this.int1 = i_int; }}
And this controller:
[HttpGet]public IActionResult Test(){ TestObj model = new TestObj(); model.TestList = new List<TestObj>(); model.TestList.Add(new TestObj("test1", 1)); model.TestList.Add(new TestObj("test2", 2)); return View(model);}
This as the cshtml:
<form asp-action="Test" asp-controller="Home"><ul> @for (int i = 0; i < Model.TestList.Count; i++) {<li><label asp-for="@Model.TestList[i].str1" /></li><li><label asp-for="@Model.TestList[i].int1" /></li><li><input asp-for="@Model.TestList[i].str1" /></li><li><input asp-for="@Model.TestList[i].int1" /></li> }</ul>
I get the input boxes but not the Labels. I have searched the web and Stack Overflow but can't find out why the labels fail when the inputs work. Any help would be appreciated.