replace character in text generated by html.displayfor(function

我的梦境 提交于 2019-12-12 14:35:35

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/24377477/replace-character-in-text-generated-by-html-displayforfunction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!