我有界面:
public interface IUserVerificationDocument
{
UserDocumentType DocumentType { get; set; }
void Save();
}
我有枚举:
public enum UserDocumentType { IdCard, Passport, DrivingLicense, ResidentsPermit }
如何使用下拉列表或类似内容为此UserDocumentType
设置值?
答案 0 :(得分:0)
那里有很多解决方案。您将在第一次搜索时找到许多内容。但这是我过去使用的简单解决方案。也许它可以帮到你。我要做的是从枚举中显示下拉列表,然后返回绑定模型上的绑定枚举。
型号:
dirent
控制器:
public enum UserDocumentType
{
IdCard,
Passport,
DrivingLicense,
ResidentsPermit
}
public class SampleViewModel
{
public UserDocumentType DocType
{
get;
set;
}
}
查看:
public ActionResult Index()
{
//Select default as Passport
var user = new SampleViewModel
{
DocType = UserDocumentType.Passport
};
return View(user);
}
public void Submit(SampleViewModel vm)
{
//vm.DocType would be what was selected when submit was clicked
}
以下是您可以运行或复制到解决方案中的可执行文件,并尝试:https://dotnetfiddle.net/DXCcHp