0
我使用EF6与我的项目。我不得不将包含两个独立类的类返回到我的视图。对不起,使用非通用名称和使用行话类名表单结果&实体框架有不同的输入名称
的模型回到我如下:
public class Configuration
{
public List<ProductEntity> ProductCategories { get; set; }
public PricingConfigurationLog PricingConfiguration { get; set; }
}
下面是使用剃刀语法窗体字段输入的一个例子。
剃刀语法
@Html.EditorFor(model => model.PricingConfiguration.PromoText, new { htmlAttributes = new { @class = "form-control" } })
HTML输出
<input class="form-control text-box single-line" id="PricingConfiguration_PromoText" name="PricingConfiguration.PromoText" type="text" value="Promotional Text">
当通过表单元素放回我的控制器来处理它们为的EntityFramework更新/插入到数据库中的列是空的。
这似乎是显而易见的元素形成名字被呈现为name="PricingConfiguration.PromoText
,而不是PromoText
这是我不知道如何改变渲染或低于约束力。
public ActionResult SaveConfiguration([Bind(Include = "ProductCode,"
+ "PromoText,"
+ "CartLimitPerDay,"
+ "CartDayAllowed,"
+ "SessionDeleteTimeMinutes,"
+ "SessionTimeoutMinutes")] PricingConfigurationLog PricingConfigurationLog)
它看起来像你想出一个方法来“皮肤此猫”。但是,作为建议,我会建议使用视图模型而不是实体。更重要的是,我会建议你尽可能地尝试并压平你的视图模型。这并不总是可行的,但它消除了您遇到的头痛类型。 – trevorc