How to capitalized first letter in Razor macro?
这是我的第一个宏,我试图将"@homenode.name"和"@page.name"的第一个字母设为大写。有没有像添加".toupper()"或".tolower()"这样的方法来完成这个任务?
这是宏代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <nav> <ul class="nav-list"> @{ var homeNode = Model.AncestorOrSelf("about"); } <li class="@homeNode.Name @Library.If(homeNode.Id == Model.Id,"selected","")">@homeNode.Name </li> @foreach (var page in homeNode.Children.Where("Visible")) { var isSelected = false; if (Model.Id == page.Id || (Model.Parent != null && Model.Parent.Id == page.Id && Model.NodeTypeAlias !="Textpage")) { isSelected = true; } <li class="@page.Name @Library.If(isSelected,"selected")"> @page.Name </li> } </ul> |
你可以用
1 | System.Globalization.TextInfo.ToTitleCase(); |
或者只是CSS
1 | text-transform: capitalize; |
号