none
Razor Pages and Display Templates RRS feed

  • Question

  • Does Razor Pages support the use of Display Templates? If so, would the DisplayTemplates folder go in Pages/Shared?

    Salome

    • Moved by CoolDadTx Monday, September 9, 2019 2:01 PM ASP.NET related
    Friday, September 6, 2019 6:07 PM

All replies

  • Yes, Razor Pages support Display Templates. Display Templates must be in a sub-folder that is named as DisplayTemplates under the Shared folder.
    Friday, September 6, 2019 6:11 PM
  • Great! Thank you for that.

    Salome

    Friday, September 6, 2019 6:27 PM
  • I am trying to create a display template for a SSN. The SSN is stored as a Varchar(9) in the database, which precludes me from simply using the DisplayFormat attribute. I have the DisplayTemplates folder under the Shared folder and I have created a file called SSN.cshtml, where I've placed the following code:

    @model PFDTrustDomain.Client

    <div>
        @Model.SSN.Insert(2, "-").Insert(5, "-");
    </div>

    In the .cshtml file I use  @Html.DisplayFor(modelItem => item.SSN)  to display the SSN, but the display mask that I am trying to create in the display template is not taking effect. Any insight into what I am missing would be greatly appreciated.


    Salome

    Friday, September 6, 2019 10:15 PM
  • Hi RavenCohoSalome,

    Thank you for posting here.

    According to your description, I have a question to confirm with you.

    What's the type of your application? ASP.NET MVC? ASP.NET Core MVC?

    Besides, I have found a reference, and you can refer it.

    Razor Page Display Template for SSN stored as a Varchar(9)

    We are waiting for your update.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, September 9, 2019 2:40 AM
  • Please post questions related to ASP.NET in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Monday, September 9, 2019 2:00 PM
  • It is a RazorPages application, built on ASP.NET Core.

    Salome

    Monday, September 9, 2019 4:16 PM