0

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

我的代码:

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

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

4

1 回答 1

3

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

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

    public CustomerViewModel()
    {
        this.Country = "Default value";
    }
}
于 2012-04-19T13:56:39.780 回答