由html.displayfor生成的文本替换字符(函数 [英] replace character in text generated by html.displayfor(function
问题描述
一个网页目前提供的设备ID与数字连字符,我想替换 -
与:
代替(也就是说,取代用冒号任何连字符),但只有在显示时间。我是pretty相信这是生成页面上显示的设备ID行:
A webpage currently gives a device ID with hyphens in the number, I want to replace -
with :
instead (that is to say, replace any hyphens with a colon), but only at display time. I'm pretty confident this is line that is generating the device ID shown on the page:
@Html.DisplayFor(Function(m) m.DeviceID)</span> <br />
是否有可能改变这种输出包括冒号呢?
Is it possible to change this output to include colons instead?
推荐答案
您可以创建一个显示模板。创建下面的局部视图〜/查看/共享/ DisplayTemplates / _DeviceWithColons.cshtml
:
You can create a display template. Create the following partial view ~/Views/Shared/DisplayTemplates/_DeviceWithColons.cshtml
:
@model string
@( Model.Replace('-', ':') )
在您的视图现在,指定:
Now in your View, specify:
@Html.DisplayFor(m => m.DeviceID, "_DeviceWithColons")
您可以稍后重新使用在需要这种显示模板。
You can then later reuse this display template where required.
这篇关于由html.displayfor生成的文本替换字符(函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!