如何从“查看模型"中获得双倍奖励? [英] 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.
以前也没问过
我有这样简单的模型
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屋!