如何从“查看模型"中获得双倍奖励? [英] How can I get a double from the View into My Model?

查看:77
本文介绍了如何从“查看模型"中获得双倍奖励?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很奇怪,我已经待了几天,没有更多的想法.

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

以前也没问过

方法是什么向在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 (包含故障输入)

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>

当我尝试添加integer时,它会正确假设,但是当我添加decimal值时,它会不会传递回到我的controller.

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.

我想念什么?

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

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

jQuery验证工作正常.

JQuery Validation works fine btw.

原始图像可以更好地查看

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

推荐答案

您将必须编写自定义模型联编程序.

You will have to write a custom model binder.

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

这篇关于如何从“查看模型"中获得双倍奖励?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆