I am new to MVC and have not found a solution for this online.
I have the html as :
@Html.DisplayFor(model => model.Address1) <br />
I want all the first letter of address1 to be capital letters e.g. Something Road instead of something road.
Now I have a class client and property Address1 and using EF to get the address as follow:
public class MyDBContext : DbContext
{
public DbSet<Client> Clients { get; set; }
}
Hope it makes sense.
To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.
toUpperCase() But this is not what we desire to achieve. To capitalize the first character of a string, We can use the charAt() to separate the first character and then use the toUpperCase() function to capitalize it.
text-transform:capitalize; will capitalize the first letter of a sentence, but if you want to also do it for commas you will have to write some javascript.
You should always capitalize the first letter of the first word in a sentence, no matter what the word is. Take, for example, the following sentences: The weather was beautiful. It was sunny all day. Even though the and it aren't proper nouns, they're capitalized here because they're the first words in their sentences.
easy solution could be
Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { class = "form-control" } })
then use below css to capitalize your first letter then you done.
.form-control {
text-transform:capitalize;
}
You could add a partial class for Client
with a property that returns Address1
in title case:
public partial class Client
{
public string TitleCaseAddress1
{
get
{
return System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(this.Address1);
}
}
}
You would then use TitleCaseAddress1
in your Razor:
@Html.DisplayFor(model => model.TitleCaseAddress1) <br />
Reference: http://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase(v=vs.100).aspx
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