如何从视图中获取双精度数据到我的模型中?
这很奇怪,我已经研究了几天了,没有更多的想法。
之前也问过也没有结果
我有像这样的简单 模型
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 验证工作正常。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将必须编写一个自定义模型绑定器。
请参阅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