How to capitalize first letter razor
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
It's best to keep the presentation layer and the data access layer separate. Create a view model that wraps or translates the ORM / entity framework objects.
public class ClientViewModel
{
private Client _dao;
public ClientViewModel(Client dao)
{
_dao = dao;
}
public string Address
{
get
{
// modify the address as needed here
return _dao.Address;
}
}
}