- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 ASP.NET Core 2.0 应用程序中,我有一个 Foo
类,其中包含很多 经典字符串或数字成员以及一个 int?预算
字段。
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace MyProj.ViewModels {
public class RecordEditViewModel {
public RecordEditViewModel() { }
public string Name { get; set; }
public string Prop1 { get; set; }
public string Prop2 { get; set; }
public string Prop3 { get; set; }
public string Prop4 { get; set; }
public string Prop5 { get; set; }
/// <summary>The project budget</summary>
//[Range(0, int.MaxValue, ErrorMessage = "Must be a positive number")]
[Display(Name = "Budget REVM"),
DataType(DataType.Currency),
DisplayFormat(NullDisplayText = "-",
ApplyFormatInEditMode = true,
DataFormatString = "{0:C}")]
public int? Budget { get; set; }
public string Prop6 { get; set; }
public string Prop7 { get; set; }
public string Prop8 { get; set; }
public DateTime CreatedOn { get; set; }
public string Prop9 { get; set; }
public string Prop10 { get; set; }
public string Prop11 { get; set; }
[Display(Name = "Attachments"), UIHint("IFromFile")]
public IEnumerable<IFormFile> Attachments { get; set; }
public string Id { get; set; }
}
}
我要
a) 以 14 000 €
格式显示
b) 以 14 000 €
格式编辑它
这是一个经典行为,以货币格式显示/编辑货币,但似乎很难在最新的 Microsoft .NET Framework 中实现。
a) CustomModelBinder
?应该为所有其余字段重写 Binder ,但我只需要预算
b) TypeConverter
?
c) 数据类型(数据类型.货币)
?似乎在编辑模式下不起作用(不显示为 int?)
我的观点:
<div class="col-md-6">
<label asp-for="Budget" class="control-label"></label>
<div>
<input asp-for="Budget" class="form-control" />
<span asp-validation-for="Budget" class="text-danger"></span>
</div>
</div>
最佳答案
我注意到 InputTagHelper有一个Format属性,这意味着可以写:
<input asp-for="Budget" asp-format="{0:C}" class="form-control" />
虽然发现这一点并不容易。 Input Tag Helper 中未提及介绍部分。最后通过ASP.NET Core MVC Input Tag Helper Deep Dive找到了
现在我明白了为什么人们说 ASP.NET Core 的文档缺乏 - 简介在一篇文章中用很长的篇幅解释了各种标签助手,解释了它们与 HTML 助手的关系,但是忽略了 Format
等重要属性。没有指向类文档的直接链接,需要进行一些挖掘才能找到它。
SO 中有很多类似的问题,答案是“你不能格式化”或提出自定义解决方案。
更新
安issue于 2017 年 7 月开放,关于发布包含货币符号的货币值。该线程很有趣,因为它解释了 asp-format
仅影响显示,因此推荐的解决方案是将符号放在 input
之外,可能使用 Bootstrap 输入组:
The recommended solution here is to place the currency indicator outside of the editable field (e.g. before or after)
也许是这样的:
<div class="input-group">
<input asp-for="Budget" asp-format="{0:#,###.00}" class="form-control" />
<span class="input-group-addon">€</span>
</div>
关于c# - 在 ASP.NET MVC Core 中显示/编辑货币,为什么这么复杂?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48205531/
条件: 我们需要我们 Magento 网站的默认显示货币是美元,Paypal(基础货币)也需要是美元(因为我们需要客户以美元支付)。 我们的 Fedex a/c 是在新加坡开设的,结果发现运费是以新加
根据 currency_str 和 created_date_time 合并两个数据帧(xrate 和 df)时遇到问题 display(xrate.info()) Int64Index: 1611
我必须匹配像 这样的值 € 6.483,00 或类似的值 18,50% 或者,再次, +65,86 % 在我起草的 Javascript 函数中: function(s) { return /^
我正在尝试将货币金额解析并存储为 BigDecimal 值。我得到了相关货币的区域设置,在大多数情况下它工作正常,但当货币是哥斯达黎加科朗时我得到了意想不到的结果。 我的哥斯达黎加客户告诉我,典型的货
在当前版本的 Excel(Office 365/2019 年 2 月)中获得近似每日外汇汇率的最简单的免费方法是什么。 我对历史数据不感兴趣,我只想要从货币 X 到货币 Y 的最后已知日汇率,并且只在
我在 spree 时遇到了麻烦,不知道如何处理。 我无法更改主要货币。 我该怎么做? 最佳答案 它在 Spree 2.0.0 中更容易,而且显然它也可以在以前的 spree 版本中工作。 转到您的 c
在我的网络应用程序中,我有一个名为“预算”的输入字段,用户可以在其中输入项目的建议预算。我需要创建一个屏蔽输入,以便在用户在输入字段中输入时自动将输入的金额转换为以下格式: 1000 10 000 1
我正在从数据库返回一个字符串,但由于数据库的编码方式,一些英镑符号 (£) 被问号取代。我想恢复井号,但不替换字符串中真正的问号。我已经设法编写了一个正则表达式来测试问号后跟数字的组合,但我不确定如何
我在使用亚马逊销售 API 时遇到问题。我在 amazon.co.uk 有一个帐户,可以正常发送产品。我在 amazon.de 有一个新帐户,除了货币外,一切都很好。 我有一个零售价为 10 英镑 (
Pharo 有什么方法可以将数字转换为单词。 例如:1200 = 一千二百而已。 实现起来并不难,只是想知道。 最佳答案 Integer>>asWords会这样做。 1200 asWords返回 'o
我有一个简单的单页网络应用程序。它从两个不同的 API 获取货币数据(以美元为单位),在成功检索后,promise 被解决,一些计算得出 GBP/Bitcoin 汇率。 我正试图找到一种干净的方法,然
我有以下简单的计算,它将两个值加在一起。这些值与使用“R”作为前缀标识的兰特(南非货币)有关。 function calculate() { var A = parseFloat(docume
使用 JavaScript,什么是将点替换为逗号的正确方法(对于欧盟货币),例如: 2000.65 将是 2000,65 而不是 2,000.65 39.20 将是 39,20 我不确定 cost.r
我在文本框中显示带有 NumberFormat 的货币符号 NumberFormat numberFormat = NumberFormat.getSimpleCurrencyFo
我已经设法从非接触式阅读器读取了一个交易事件,使用 现在我的 Activity 打开了,我被困在那个点上,因为我认为我的 Intent 中会有一些数据,比如 amou
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 Improve th
这个问题在这里已经有了答案: Why not use Double or Float to represent currency? (16 个答案) 关闭 3 年前。 我的应用程序中的一些计算有问题
我使用 Jruby(反正就是 ruby,在 jvm 下运行 :D )和马拉松测试(一个 java swing 应用程序),我在处理货币数字时遇到了一些麻烦。 我不使用 Rails(不知道我是否可以
我正在尝试删除 、 或 之后的尾随零。 以一种货币表示,仍然保留货币符号。例如,€90.00 到 €90、90.00€ 到 90€ 和 €90.33 到 €90.33。 示例如下: $('.produ
我想将带小数点的数字(以货币计)转换成单词 例如:12345.60--> 一万二千三百四十五美元六十美分 我从 http://www.csharp-tutorials.info/2016/04/con
我是一名优秀的程序员,十分优秀!