如何从视图中获取双精度数据到我的模型中?

发布于 2024-11-10 08:56:06 字数 2571 浏览 0 评论 0原文

这很奇怪,我已经研究了几天了,没有更多的想法。

之前也问过也没有结果

怎么回事向在 EF 中复制的 SQL 添加十进制数?

我有像这样的简单 模型

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>

当我尝试添加整数时,它假设正确,但是当我添加小数值时,它只是获胜' t 传回我的控制器

我错过了什么?

我什至尝试将CultureInfo设置为正确的国家/地区,但不幸的是,

JQuery 验证工作正常。

原始图片以便更好地查看

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

This is weird and I'm being on this for a couple days with no more ideas.

Even asked before with no results as well

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

I have my simple Model like this

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; }
}

And the HTML is scaffolded as Create containing the trouble input as

<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>

When I try to add an integer, it assumes correctly, but when I add a decimal value, it just won't pass back into my controller.

What am I missing?

I even tried to set the CultureInfo to the correct country, but no luck

JQuery Validation works fine btw.

original image for better viewing

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

街道布景 2024-11-17 08:56:06

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

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

You will have to write a custom model binder.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文