ASP.NET MVC 5 Nullable boolean as dropdown - 参数

时间:2016-10-05 05:22:27

标签: c# asp.net asp.net-mvc

我的模型中有一个可以为空的bool

public bool? Property { get; set; }

我通过EditorFor

呈现它
@Html.EditorFor(model => model.Property)

如何将类form-control添加到呈现的选择中?如何本地化字符串Not setTrueFalse?或者更好的我如何用自定义字符串替换它们?

2 个答案:

答案 0 :(得分:2)

<script type="text/javascript">
var newWin;
function newWindow()
{
    newWin=window.open('http://www.google.co.in','_blank');
    setTimeout(function(){newWin.close()}, 5000);
}
</script>
<button onclick="newWindow()">open Window</button>

答案 1 :(得分:1)

  You can try with below code:  

         @Html.DropDownListFor(m => m.Property, 
                    new List<SelectListItem>(){                       
                    new SelectListItem { Value = "False", Text = "False" },
                    new SelectListItem { Value = "True", Text = "True" }
    },"Not set",new { @class = "form-control" })