У меня есть простая одностраничная страница ASP. NET Приложение Core Razor, в котором есть "select", которое я заполняю из переменной Model. Значения в переменной Model очищаются ко времени, когда я проверяю их в методе OnPost (). (Переменная с именем machineModel возвращается очень хорошо, но переменная с именем machineModels в модели очищается сообщением.) Что это делает?
Вот как Index.cs html выглядит следующим образом:
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-left">
<form enctype="multipart/form-data" method="post">
Model: <select name="machineModel" asp-for="machineModel" asp-items="Model.machineModels" required></select>
<input type="submit" asp-page-handler="Download" value="Download certificate" />
</form>
</div>
Вот как выглядит Index.cs html .cs:
[BindProperties]
public class IndexModel : PageModel
{
public string machineModel { get; set; }
public List<SelectListItem> machineModels = new List<SelectListItem>();
// In some other function in the class the machineModels variable is filled (several times) ...
string modelStr = reader.GetAttribute("value");
int numMachineModels = machineModels.Count;
string machineModelIndexStr = numMachineModels.ToString();
machineModels.Add(new SelectListItem { Text = modelStr, Value = machineModelIndexStr, Selected = true });
// And here's the Post method ...
public IActionResult OnPostDownload()
{
// Doesn't matter what's in here, machineModels is already cleared at this point
return Page();
}
}
Заранее благодарен за любую помощь, которую вы можете оказать, Рич