填写EditorFor Field

时间:2012-04-19 13:41:52

标签: c# .net asp.net-mvc html-helper editorfor

我正在尝试使用默认值填充editorfor字段。请帮忙

我的代码:

<div class="editor-label">
        @Html.LabelFor(model => model.Country)
</div>
<div class="editor-field">
        @Html.EditorFor(model => model.Country)
</div>

该模型由实体框架通过我的SQL数据库创建。

1 个答案:

答案 0 :(得分:3)

为什么不使用模型的构造函数?

public class CustomerViewModel
{
    public string Country { get; set; }

    public CustomerViewModel()
    {
        this.Country = "Default value";
    }
}
相关问题