The currency formatter is not working in ASP.Net MVC. The input field in the UI is showing a blank in the field when there is a value of 100.00 in the Model.ClientLicense.Rate variable.
FYI - Model.ClientLicense.Rate is a decimal value
Here is the razor code
<input name="Rate" type="number" class="form-control" value=#(string.Format("{0:C}", Model.ClientLicense.Rate) ) >
solution - changed type="number" to "text"
can you try this, I always use it when i need to show currency format hope it works to you.
#(String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C2}", Convert.ToDouble(Model.ClientLicense.Rate)))
also I think the type attribute of the input might affect, try changing the type to text
Related
I have an ASP.NET MVC 5 application using Razor. When it loads, it displays saved data in input fields. This works fine in IE 11, but when viewing in Microsoft Edge 90.0.818.51, the values are not being displayed.
When I view the source I see the value is set, but am not sure why it's not displaying in Edge. Has anyone been experiencing this?
<input class="small-input form-control text-right" data-val="true" data-val-regex="The field must match the regular expression '^[-+]?(\d+(\.\d*)?|\.\d+)[%]?$'." data-val-regex-pattern="^[-+]?(\d+(\.\d*)?|\.\d+)[%]?$" id="SignificantActivityInputs" name="SignificantActivityInputs" type="number" value="10%" />
There are other fields that are displaying the text. The difference I can see with them are:
They have an associated field that is of type "hidden"
The "main" field is of type "text" where the ones that aren't displaying are of type "number" as shown above.
Has anyone else experienced this?
The type should be text, instead of number
<input class="small-input form-control text-right"
data-val="true"
data-val-regex="The field must match the regular expression '^[-+]?(\d+(\.\d*)?|\.\d+)[%]?$'."
data-val-regex-pattern="^[-+]?(\d+(\.\d*)?|\.\d+)[%]?$"
id="SignificantActivityInputs"
name="SignificantActivityInputs"
type="text"
value="10%" />
I am setting the value "30 Day Report" to
<input type="text" value=#Model.rpt.ReportDescription.ToString() />
But the value ends up being only "30". I verified this using chrome developer tools. It works if I use #Html.TextBox() or #Html.TextBoxFor() so I know the value comes through, but I don't want to use any html helpers. How can I make the value display properly without html helpers?
Thank you.
You forgot the quotes " around the value:
<input type="text" value="#Model.rpt.ReportDescription.ToString()" />
// ^ ^
I've got a form where I want to edit some user data.
So the already stored data is put as th:value and after sending I validate with spring validation and want to give back the form on wrong input. I want the input field to have the value of the input by the user but it always gives me the stored input instead.
That's how an input field looks like
<input type="text" th:value="${product.name}" th:field="*{name}" th:errorclass="fieldError"/>
If the form is loaded the first time the input fields should have the value of the already stored data.
If it's loaded after submit and with an validation error, the input fields should have the value of the user's input.
Is there a way to to that?
Thanks!
Attribute th:field will replace attributes value, id and name in your input tag.
Instead, use plain th:id, th:value and th:name without using th:field. Then you will get what you wanted.
Then it will look like:
<input type="text" th:value="${product.name}" th:name="name" th:id="name" th:errorclass="fieldError"/>
Similar answer is here: How to set thymeleaf th:field value from other variable
Because Attribute th:field is Combination of both th:name and th:value
So, either use this:
<input type="text" th:value="${product.name}" th:name="name" th:errorclass="fieldError"/>
Or this:
<input type="text" th:field="*{name}" "th:errorclass="fieldError"/>
Using th:field or value, id and name is ok. if you user th:field, you can write this:
<input type="text" th:field="${product.name}" th:value="${product.name}" "th:errorclass="fieldError"/>
You have error in your controller (you set wrong value to *{name}), if the input value is wrong after validation error.
I am trying to understand the level of support of <input type="date"> in iOS. I tested it with an iPhone 4 with iOS 7.0.3, even if I specify a min attribute the date picker lets me choose a date before the constraint.
The HTML code is this:
<input type="date" id="checkIn" name="checkIn" class="form-control input-sm" value="2014-05-26" min="2014-05-26" data-date-format="YYYY-MM-DD" data-date-minDate="2014-05-26" placeholder="yyyy-mm-dd">
The data attributes are set for this datepicker but I detect the field support via Modernizr so I'm really sure it does not interfere in any case with the datepicker.
So the question is: did I do something wrong or is the date field lacking constraints support?
I have been having the same issue. It looks like although using <input type="date"> does render a date field. The min attribute is not working.
This website clearly states that there is support lacking.
From the website,
Partial support in iOS refers to a lack of support for attributes like step, min, or max. You have not done anything wrong.
Hope this answers your question.
Hi I tried adding a range from 1-10 to a field in my model and it caused 2 mini arrows to appear to the right of my editor field that increment and decrement the value inside by 1. I would like to know how to remove these arrows. Any advice would be great. Thanks
Instead of using #Html.Editor html helper, use #Html.TextBox, this will solve your problem.
Because the property type is integer, if you'r using #Html.Editor, it will generate html like below:
<input type="number" id="Data" />
Notice the input element type is number, if your browser support HTML 5, it will show two arrows to the right. It's an html 5 feature.
But, if you're using #Html.TextBox, it will generate html like below:
<input type="text" id="Data" />
This time the type is text, it will not show the arrows.