问题
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