Skip to content
A VB.NET Razor For ASP.NET MVC Core and ASP.NET Razor Pages. For more advanced implementation, look at
Visual Basic .NET HTML CSS JavaScript
Branch: master
Clone or download
Latest commit c25091e Jun 2, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
VBRazorSample 31 Mars 2019 Mar 31, 2019
VbRazor 23 Mars 2019 Mar 23, 2019
WebApp1 31 Mars 2019 Mar 31, 2019
.gitattributes Add .gitignore and .gitattributes. Mar 21, 2019
.gitignore Add .gitignore and .gitattributes. Mar 21, 2019 Update Jun 2, 2019
VB.NET MVC Core Sample.sln 31 Mars 2019 Mar 31, 2019


I use a better way in to make use of tag helpers and other Razor capabililties.

This is a working VB.NET ASP.NET MVC Core Razor sample! I implemented a simple VBRazorViewEngine in the VbRazor project. To use VBRazorViewEngine in the web project: 1- Add a reference to VBRazor.dll 2- Added these two statements to the Startup.ConfigureServices method:

services.AddTransient(Of IConfigureOptions(Of MvcViewOptions), VBRazor.VBRazorMvcViewOptionsSetup)()
services.AddSingleton(Of IViewEngine, VBRazor.VBRazorViewEngine)()

3- Creat a Razor Virew class: The VBRazor is just a VB class that implements the IVBRazor Interface:

Public Interface IVBRazor
    ReadOnly Property Razor As String

End Interface

The Razor property uses the xml literals to compose the HTML code and returns it as a string.. Example:

Imports VbRazor

Public Class IndexView
    Implements IVBRazor

    Dim students As List(Of Student)

    Public Sub New(students As List(Of Student))
        Me.students = students
    End Sub

    Public ReadOnly Property Razor As String Implements IVBRazor.Razor
            Dim x = <html>
                        <h3> Browse Students</h3>
                        <p>Select from <%= students.Count() %> students:</p>
                            <%= (Iterator Function()
                                     For Each std In students
                                         Yield <li><%= std.Name %></li>
                                 End Function)() %>
            Return x.ToString()

        End Get
    End Property
End Class

4- To use the Razor View Class from the Controller: in the action method, pass an instance of the razor class to the View method, and pass the model data to its constructor:

Public Function Index() As IActionResult
    Return View(New IndexView(Students))
End Function

And that’s all! If you run the project, you will see the web page that VBRazor composed!.. In this example, it will be as in the image:


This was really easy, but needs more work, so I hope you start contribute to this project to make it a real productive tool! The first thing to do, it to create a VB.NET template for ASP.NET MVC Core. I had to create a C# project then convert it to VB!

The second thing to do, is to add intellisense support for html attributes in xml literals in VB!

We need to try more advanced pages with JavaScript and other components. I hope VB team give us the support wee need to make the most of xml literals.

You can’t perform that action at this time.