簡體   English   中英

DataFormatString = "{0:N}" 不適用於 Model MVC

[英]DataFormatString = "{0:N}" not working on Model MVC

對於 CurrentCulture 函數中的數字類型“int”,我想要在 Milles 上使用點和逗號。 我正在嘗試使用 DataFormtString 但它不起作用。 例如:1234567 ==> 123.456.789

我正在使用 MVC,我想格式化表格、輸入等中的數字。

.Replace() 或類似的東西不是解決方案,我希望它具有 CurrentCulture 的功能。

例如:

    [DisplayName("Test")]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:N}")] // Not working
    public int? Example{ get; set; }

在視圖中:

        <span class="text">@Model.Example</span>
        <input asp-for="Example" class="form-control form-control-sm" />

根據你的描述,我在我這邊創建了一個測試demo,發現已經給input設置了值,但是因為input類型的值導致無法顯示。

我建議您可以將輸入類型設置為文本,然后重試。

更多細節,您可以參考以下代碼:

<span class="text">@Model.Example</span>

<input asp-for="Example" class="form-control form-control-sm" type="text" />

結果:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM