我正在尝试使用默认值填充editorfor字段。请帮忙
我的代码:
<div class="editor-label">
@Html.LabelFor(model => model.Country)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Country)
</div>
该模型由实体框架通过我的SQL数据库创建。
答案 0 :(得分:3)
为什么不使用模型的构造函数?
public class CustomerViewModel
{
public string Country { get; set; }
public CustomerViewModel()
{
this.Country = "Default value";
}
}