当模型值为空/空时,我想在剃刀视图中设置文本框的默认值。这就是我设置默认值的方式,但它目前正在覆盖模型的值,即使它存在:
<div class="form-group">
@Html.LabelFor(Function(model) model.PostAction, htmlAttributes:=New With {.class = "control-label col-md-2"})
<div class="col-md-10">
@Html.EditorFor(Function(model) model.PostAction, New With {.htmlAttributes = New With { .Value = "Active", .class = "form-control"}})
@Html.ValidationMessageFor(Function(model) model.PostAction, "", New With {.class = "text-danger"})
</div>
</div>
我希望默认值是一个可选值,仅在模型值为 null 时才设置