在Html.DisplayNameFor中转换为小写

Nos*_*mus 4 razor asp.net-mvc-5

它应该很简单,但看不到它......我有以下内容:

@Html.EditorFor(model => model.FullName, new
                        {
                            htmlAttributes = new
                            {
                                @class = "form-control",
                                placeholder = "Please type your " + Html.DisplayNameFor( model => model.FullName),
                                data_bind = "value: product.fullname"
                            }
                        })
Run Code Online (Sandbox Code Playgroud)

当我输入时,Html.DisplayNameFor( model => model.FullName.ToLower())我得到一个例外

System.Web.Mvc.dll中出现"System.InvalidOperationException"类型的异常,但未在用户代码中处理

附加信息:模板只能用于字段访问,属性访问,单维数组索引或单参数自定义索引器表达式.

我怎么能在里面操纵我的字符串Html.DisplayNameFor

Pav*_*eja 8

DisplayFor()extension方法返回一个MvcHtmlString,所以你可以使用返回值转换为字符串ToString()然后再使用ToLower()

placeholder = "Please type your "
    + Html.DisplayNameFor(model => model.FullName).ToString().ToLower()
Run Code Online (Sandbox Code Playgroud)