我有一个模型:
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
}
}
我如何从我的下拉列表中的文本? 谢谢