4

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?

hjavaher
  • 2,589
  • 3
  • 30
  • 52
notAduck
  • 190
  • 1
  • 3
  • 13

1 Answers1

4

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.

Adrian Thompson Phillips
  • 6,893
  • 6
  • 38
  • 69
  • thanks to this post I managed to get rid of underscore in the Enum `@model SkillLevelEnums @( Model.ToString().Replace('_', ' ') )` – gdogra Apr 12 '22 at 22:52