[英]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即使之前问过也没有结果
What's the way to add decimal number to SQL that replicate in EF?
将十进制数添加到在 EF 中复制的 SQL 的方法是什么?
I have my simple Model like this我有我这样的简单Model
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并且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>
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
.当我尝试添加
integer
时,它假定正确,但是当我添加decimal
值时,它不会传回我的controller
。
What am I missing?
我错过了什么?
I even tried to set the CultureInfo
to the correct country, but no luck我什至尝试将
CultureInfo
设置为正确的国家,但没有运气
JQuery Validation works fine btw. JQuery 验证工作正常。
original image for better viewing原图更好看
http://www.balexandre.com/temp/2011-05-28_1046.png http://www.balexandre.com/temp/2011-05-28_1046.png
You will have to write a custom model binder.您必须编写自定义 model 活页夹。
See http://haacked.com/archive/2011/03/19/fixing-binding-to-decimals.aspx见http://haacked.com/archive/2011/03/19/fixing-binding-to-decimals.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.