【问题标题】:How can I get a double from the View into My Model?我怎样才能从视图中获得双倍到我的模型中?
【发布时间】:2011-05-28 08:35:11
【问题描述】:

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

即使之前问过也没有结果

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 被构建为 Create,其中包含故障输入

<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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 2012-11-25
      • 1970-01-01
      • 2019-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-04
      • 1970-01-01
      相关资源
      最近更新 更多