Вот рабочая демонстрация, как показано ниже:
1.Модель:
public class TestModel
{
public int Id { get; set; }
public string Name { get; set; }
public Select Select { get; set; }
}
public class Select
{
public int SelectId { get; set; }
public string Name { get; set; }
}
2.Просмотр:
@model TestModel
<div class="row">
<div class="col-md-4">
<form asp-action="Example">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Name" class="control-label"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Select.Name" class="control-label"></label>
<select asp-for="Select.SelectId" asp-items="ViewBag.SList"></select>
<span asp-validation-for="Select.Name" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
3.Контроллер:
public class HomeController : Controller
{
public IActionResult Index()
{
List<Select> selectList = new List<Select>()
{
new Select(){ SelectId=1, Name="aaa"},
new Select(){ SelectId=2, Name="bbb"},
new Select(){ SelectId=3, Name="ccc"},
new Select(){ SelectId=4, Name="ddd"},
};
ViewBag.SList = new SelectList(selectList, "SelectId", "Name");
return View();
}
[HttpPost]
public IActionResult Example(TestModel model)
{
var selectedValue = model.Select.SelectId;// Or model.Name
//do your stuff...
}
Результат: