Embed markdown into a razor view using asp.net core

1 minute read

Application overview Mardown is creeping up and has become a standard for documentation. How to embed markdown into a razor view will be shown in this application. Let’s have a look on the implementation of the project.

Tools and Technology used The following tools and technologies has been used for this application

  • Visual Studio 2019
  • Visual C#
  • NuGet package “Westwind.AspNetCore.Markdown”
  • ASP.NET Core MVC
  • Razor view engine

Step1: Select ASP.NET Core Web Application
Select File->New->Project->ASP.NET Core Web Application

Step2: Choose project and solution name
Type project and solution name as “MarkdownToHTMLv02”

Step 3: Select project template

  • Select project template as Web Application (Model-View-Controller)
  • Click create button

Step 4: Install Nuget package “Westwind.AspNetCore.Markdown”
Run the following command in package manager console

PM> Install-Package Westwind.AspNetCore.Markdown

Step 5: Register TagHelper

Add the following TagHelper in Views->_ViewImports.cshtml

@addTagHelper *, Westwind.AspNetCore.Markdown

Step 6: Apply markdown tag
Now apply markdown tag in Views->Home->Index.cshtml

<h3>Markdown TagHelper Block</h3>

<markdown normalize-whitespace="true">
    ## This is a markdown title
    * Item 1
    * Item 2
    The current Time is:


Step 7: Build and run the application

Now the application is ready to run. Build and run the application and watch the html output which you is writtern in the markdown tag.

Source Code