如何从View into My Model获得双倍?

时间:2011-05-28 08:35:11

标签: c# validation asp.net-mvc-3 viewmodel

这很奇怪,我在这几天没有更多的想法。

甚至之前也没有问过结果

  

What's the way to add decimal number to SQL that replicate in EF?

我有这样简单的模型

public class SalesModelView
{
    public int SaleId { get; set; }
    public int ShopId { get; set; }

    public DateTime SaleDate { get; set; }

    public int Hours { get; set; }
    public double Sales { get; set; }
    public double Treatments { get; set; }

    public double Turnover { get; set; }
    public double TurnoverHour { get; set; }
    public double Efficiency { get; set; }
}

HTML 的搭建为创建,其中包含麻烦输入

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

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

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

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

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

当我尝试添加integer时,会正确,但是当我添加decimal值时,将无法通过回到我的controller

  

我缺少什么?

我甚至尝试将CultureInfo设置为正确的国家/地区,但没有运气

JQuery验证工作正常。

original image for better viewing

http://www.balexandre.com/temp/2011-05-28_1046.png

1 个答案:

答案 0 :(得分:0)

您必须编写自定义模型装订器。

请参阅http://haacked.com/archive/2011/03/19/fixing-binding-to-decimals.aspx