Использование Visual Studio 2017, .Net Core 2.1, веб-сайт
С этой моделью
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;
}
}
И с этим контроллером:
[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);
}
Это как 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>
Я получаю поля ввода, но не метки.Я искал в Интернете и переполнении стека, но не могу выяснить, почему ярлыки не работают, когда входы работают.Любая помощь будет оценена.