Display/Edit a Currency in ASP.NET MVC Core, why so complicated?

后端 未结 2 744
傲寒
傲寒 2021-01-14 03:20

In an ASP.NET Core 2.0 application, I have a Foo class with a lot of classical string or numeric members and also a int? Budget fi

2条回答
  •  一向
    一向 (楼主)
    2021-01-14 03:32

    I noticed that InputTagHelper has a Format property, which means one can write :

    
    

    Finding that though was not easy. It wasn't mentioned in the Input Tag Helper section of the intro. In the end I found it through ASP.NET Core MVC Input Tag Helper Deep Dive

    Now I understand why people say ASP.NET Core's documentation is lacking - the intro goes to great lenghts to explain the various tag helpers in a single article, explains their relation to HTML Helpers, but ommits significant properties like Format. Without direct link to the class's documentation, it takes a bit of digging to find it.

    There are quite a few similar questions in SO with answers that say "you can't format" or propose custom solutions.

    UPDATE

    An issue was opened on July 2017 about POSTing currency values that included a currency symbol. The thread is insteresting as it explains that asp-format only affects display, so the recommended solution is to put the symbol outside the input, possibly using Bootstrap input groups :

    The recommended solution here is to place the currency indicator outside of the editable field (e.g. before or after)

    Perhaps something like this:

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题