I have the following textbox in my View
:
The code for the placeholder:
@Html.TextBoxFor(m => m.Listing.Location.AddressLine1, new {@placeholder="Address Line 1 - Required"})
Question: How do I make the text "Required" in RED.
you have to use TextBoxFor instead of it try this code: @Html. TextBoxFor(model => model. ToEmail, new {placeholder="Enter Your EmailID...!!!"})
IMO the main difference is that Textbox is not strongly typed. TextboxFor take a lambda as a parameter that tell the helper the with element of the model to use in a typed view. You can do the same things with both, but you should use typed views and TextboxFor when possible.
You can't do this with a text field. You have no control over the formatting of only some portions of the HTML5 placeholder
attribute. Not to mention that if you want to achieve multicolor text you can no longer use a text field or textarea. You will have to use an element with contenteditable="true"
attribute and write your custom plugin.
Here's for example how the markup might look like:
<div contenteditable="true">
Address Line 1 - <span style="color: red">Required</span>;
</div>
But since this is a div
element you will now have to back it up with a corresponding hidden field so that the value is sent to the server. Also when the value of this field changes you need to resynchronize the hidden field value as well. It will be a lot of work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With