英文:
How to do not allow scientific formatting for numbers in @Html.TextBoxFor() method?
问题
我遇到了同样的问题,当使用该方法时,它会将小的双精度数转换为科学计数法(0.000028 -> 2.8e-005)。
我对此进行了一些研究,没有找到任何可以让我继续使用@Html.TextBoxFor()并按照我想要的方式显示数据的方法。基本上,我看到的解决方案要么是将元素更改为Html.EditorFor()或Html.DisplayFor(),并在它们上创建一些模板。
由于项目可能在一个表单上有数百个输入框,我找到的解决方案会过于复杂。有没有办法保持这种方法并按照我想要的方式呈现数据?
英文:
as there I have the same problem, while using the method it converts small double to scientific notation (0.000028 -> 2.8e-005).
I did a little research on that and didn't find anything that would let me use @Html.TextBoxFor() still and show data as I want. Basically, the solutions I see are either change the element to Html.EditorFor() or Html.DisplayFor() and create some template on them.
As the project may have hundreds of input boxes on one form the solution I've found will be an overkill. Is there any way to keep the method and render data as I want?
答案1
得分: 1
我认为以下可能是解决方案:
@Html.TextBoxFor(m => m.Data, "{0:#,0.######}")
其中 Data
是 double
类型。
此外,可以定义 number
类型以改进客户端验证。例如:
@Html.TextBoxFor(m => m.Data, "{0:#,0.######}", new { type = "number", @min=-99999, @max=99999, @step="any" })
英文:
I suppose the following might be solution:
@Html.TextBoxFor(m => m.Data, "{0:#,0.######}")
Where Data
is double
.
<hr>
Moreover, the number
type might be defined to improve validation on the client side. For example:
@Html.TextBoxFor(m => m.Data, "{0:#,0.######}", new { type = "number", @min=-99999, @max=99999, @step="any" })
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论