我正在使用 Entity Framework (v4)实体。我有一个名为Car的实体,类型为Year,类型为integer。 Year属性不允许NULL。我的“创建” View 中具有以下内容:

<%= Html.TextBoxFor(model => model.Year) %>

由于其他要求,我需要在CarController的HttpGet Create操作中返回一个新的Car对象。

当前,由于Year属性不允许NULL,因此Year文本框中显示零。我想在“创建” View 中显示一个空的文本框。我该怎么做呢?

最佳答案

使用HTML属性重载。在 Razor 中将是:

@Html.TextBoxFor(model => model.Year, new { Value = "" })

关于entity-framework - 在EF实体的not-null属性中使用Html.TextBoxFor显示空文本框,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2703860/

10-14 10:28