开发者

How can I get a double from the View into My Model?

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

开发者_StackOverflow

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


You will have to write a custom model binder.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜