我有一个模型:
public class DocumentModel
{
public int TypeID { get; set; }
public List<SelectListItem> DocumentTypes { get; set; }
}
我有一个看法:
@Html.DropDownListFor(x => x.TypeID, Model.DocumentTypes, "- please select -")
我填充我的下拉列表
var model = new DocumentModel();
model.DocumentTypes = GetDocumentTypes();
private static List<SelectListItem> GetDocumentTypes()
{
var items = new List<SelectListItem>
{
new SelectListItem
{Text = @"Text #1", Value = "1"},
new SelectListItem
{Text = @"Text #2", Value = "2"},
};
return items;
}
回发表单时,我有一个控制器操作:
[HttpPost]
public void UploadDocument(DocumentModel model)
{
if (ModelState.IsValid)
{
// I want to get the text from the dropdown
}
}
如何从我的下拉列表中获取文本?谢谢