set textbox value with razor only uses numeric portion - asp.net-mvc

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()" />
// ^ ^

Related

How to format date using message.properties on thymeleaf?

I'm using thymeleaf and I need to format this field to a specific date. It's working the way it is, but I need the date format to be into the message.properties.
So this is working:
<input type="text" id="dtFrom" class="form-control " placeholder="yyyy-MMM-dd" th:attr="placeholder=''+#{default.date.format}+''" autocomplete="off" th:name="startDate" th:value="${srchCmd.startDate}?${#dates.format(srchCmd.startDate, 'yyyy-MMM-dd')}">
</input>
But instead I need something like this:
<input type="text" id="dtFrom" class="form-control " placeholder="yyyy-MMM-dd" th:attr="placeholder=''+#{default.date.format}+''" autocomplete="off" th:name="startDate" th:value="${srchCmd.startDate}?${#dates.format(srchCmd.startDate, #{default.date.format})}">
</input>
When I select the date instead of having the date formatted on the text input I have this:
??welco12e.12essage_en_US??
How is the right way to use #{} inside ${}? Not sure if that's the problem though.
My usage is slightly different, but, I was able to get the basic concept to work using:
<span th:text="${#dates.format(timestamp, #messages.msg('timestampFormat'))}">10/31/2018 11:59:07 -0500</span>
where my messages.properties file contains a (valid) value for 'timestampFormat', and timestamp is an available Model attribute (type Instant, for java8).
Note that I had to use #messages.msg('key') explicitly here.

In label newline character is not working

Hi i have the code like this
<label class="floating">
<input name="role[permissions][]" type="checkbox" value="project_reopen
asd">
Project reopen
Asd
</label>
In my Ruby code I put the value like this
puts 'project_reopen'+"\n"+'asd'.to_s.humanize
The value is displaying the line break but in view its not working
om/I7NDj.png
In HTML, like breaks are different. You should use <br> for that purpose:
<input name="role[permissions][]"
type="checkbox"
value="project_reopen<br>asd">
You should not expect any whitespace to be preserved in HTML as typed. Conseq spaces will be squeezed, etc.
To print the string that comes from not trusted source (like DB,) one should explicitly tell Rails it’s fine to use it as is:
value="<%= #string.html_safe %>"

Currency formatting not working in ASP.Net MVC

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

Insert text with space from resource file to the value property of input in MVC 4

I have the following code to insert text from resource file to the value property of input in MVC 4:
<input type="submit" value=#EXAMPLE.Resources.Account.Login.SignInText />
The text is in spanish: "Iniciar Sesion", however only shows "Iniciar" because between "Iniciar" and "Sesion" exist one space character.
Any Idea?
Thanks,
Add quotes around your attribute value:
<input type="submit" value="#EXAMPLE.Resources.Account.Login.SignInText" />
You should ALWAYS use quotes for attributes IMHO, don't omit them.

How to add specific attribute (like "multiple") to Thymeleaf templates?

I have this:
<input id="fileupload" type="file" name="files[]" data-url="rest/controller/upload" multiple>
and I need to make it work in a Thymeleaf template. I have the data-url part figured out but I keep getting an error on the word "multiple". This is needed to allow multiple selection in the file selection window.
I have looked everywhere and have not come across an answer.
EDIT:
If you are not familiar, here is the "multiple" attribute.
http://www.w3schools.com/tags/att_input_multiple.asp
The Standard Dialect of Thymeleaf includes attributes that allow you to set these attributes by evaluating a condition, so that if evaluated to true, the attribute will be set to its fixed value, and if evaluated to false, the attribute will not be set:
e.g for checkedattribute:
<input type="checkbox" name="active" th:checked="${user.active}" />
you have to use:
th:multiple
e.g
<input id="fileupload" type="file" name="files[]" th:multiple="{condition}">
see a tutorial here.

Resources