Skip to content Skip to sidebar Skip to footer

Replace Character In Text Generated By Html.displayfor(function

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.

Solution 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.

Post a Comment for "Replace Character In Text Generated By Html.displayfor(function"