MVC剃刀需要得到子串 [英] MVC Razor need to get Substring

查看:79
本文介绍了MVC剃刀需要得到子串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的看法如下里面

     @Html.DisplayFor(modelItem => item.FirstName)

我需要的名字的第一个字母。

I need to get the first initial of the First Name.

我试过

    @Html.DisplayFor(modelItem => item.FirstName).Substring(1,1) 

但它似乎并没有工作。我得到以下错误:..'System.Web.Mvc.MvcHtmlString不包含子串和无扩展名

but it does not seem to work. I get the following error: .. 'System.Web.Mvc.MvcHtmlString' does not contain a definition for 'Substring' and no extension

推荐答案

如果你只想要显示的第一个字符 item.FirstName 为什么不这样做:

If you are only wanting to display the first character of item.FirstName why not do:

@Html.DisplayFor(modelItem => item.FirstName.Substring(1,1))

您有它的关闭括号错误的一边。

You have it the wrong side of the closing bracket.

这篇关于MVC剃刀需要得到子串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆