想在控制器下拉列表中選擇值後點擊提交按鈕無法獲得選擇的值當點擊在asp.net mvc5提交按鈕
查看部分: -
@Html.DropDownListFor(m => m.ExportFormat, new List<SelectListItem>()
{
new SelectListItem(){Value="PDF", Text = "PDF"},
new SelectListItem(){Value=".CSV", Text = ".CSV"},
new SelectListItem(){Value="Excel", Text = "Excel"}
}, "Select Format", new { @class = "form-control editable" })
<input type="submit" value="Export file" class="btn btn-primary" name="Command" />
控制器部分: -
[AllowAnonymous]
public ActionResult Reports(ReportsModel model,string Command)
{
if(Command=="PDF")
{
}
else if(Command==".CSV")
{
}
else if(Command=="Excel")
{
}
}
是否'ReportsModel'包含一個屬性'ExportFormat'?如果是這樣,它將與選定的選項綁定。您的提交按鈕沒有'value'屬性,因此它不會發布值 - 'Command'的值將始終爲'null'。但是,爲什麼你要使用它來獲得'ExportFormat'屬性的值呢? –