【发布时间】:2020-07-13 19:50:04
【问题描述】:
我有一个使用 SelectList 填充数据的下拉列表。我正在将下拉列表中的数据传递到我的第二页(NewPage)。我的目标是从 Controller 中的 SelectList 中获取第三个参数(FirstName)。
查看
<select name="dropdown1" asp-items="@(new SelectList(ViewBag.message, "ID", "FirstName"))"></select>
控制器:
[HttpGet("[action]")]
public IActionResult NewPage(string dropdown1)
{
string firstName = Request.Form["dropdown1"];
int intID = Convert.ToInt32(dropdown1);
List<PersonModel> data = new List<PersonModel>()
{
new PersonModel()
{
ID = intID,
FirstName = firstName
}
};
TempData["Data"] = System.Text.Json.JsonSerializer.Serialize(data);
return RedirectToAction("NewPage", "NewPage");
}
我的控制器中的字符串变量 firstName 为空。我收到内容类型无效的错误。我通常使用 Request.Form[""] 从字段中获取文本,但在这种情况下它似乎不起作用,因为这是一个选择而不是输入框。关于如何从我的选择框/SelectList 的第三个参数中获取文本的任何建议?感谢您的宝贵时间!
【问题讨论】:
标签: asp.net-core model-view-controller dropdown http-get selectlist