I'm trying to achieve a very common scenario whereas given a list of options to choose from, the last one says "Other" and when selected the user is presented with the input field to specify what "other" is.
在我的例子中,它是一个人的头衔列表:
public List<string> TitleList
{
get
{
return new List<string> { "Mr", "Mrs", "Miss", "Dr", "Other" };
}
}
我想要做的是:
@Html.DropDownListFor(m => m.Title, new SelectList(Model.TitleList), "Please select...") @Html.TextBoxFor(m => m.Title)
我希望模型在 DropDownLis 中选择“Other”时绑定 TextBox 值,并在所有其他情况下绑定到 DropDownList 中的选定项目。
这是否可以在不在模型上添加额外属性的情况下实现?