--------------------------------------------------------------------------------
/RazorPages1/wwwroot/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VBAndCs/VB.NET-Razor/HEAD/RazorPages1/wwwroot/favicon.ico
--------------------------------------------------------------------------------
/VBRazorSample/wwwroot/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VBAndCs/VB.NET-Razor/HEAD/VBRazorSample/wwwroot/favicon.ico
--------------------------------------------------------------------------------
/VbRazor/ILayoutRazor.vb:
--------------------------------------------------------------------------------
1 | Public Interface ILayoutRazor
2 | Inherits IRazor
3 |
4 | Property Body As XElement
5 | End Interface
6 |
--------------------------------------------------------------------------------
/WebApp1/Views/_ViewImports.cshtml:
--------------------------------------------------------------------------------
1 | @using WebApp1
2 | @using WebApp1.Models
3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4 |
--------------------------------------------------------------------------------
/RazorPages1/Pages/_ViewImports.cshtml:
--------------------------------------------------------------------------------
1 | @using RazorPages1
2 | @namespace RazorPages1.Pages
3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4 |
--------------------------------------------------------------------------------
/VBRazorSample/Views/_ViewImports.cshtml:
--------------------------------------------------------------------------------
1 | @using WebApplication1
2 | @using WebApplication1.Models
3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4 |
--------------------------------------------------------------------------------
/VBRazorSample/Models/Student.vb:
--------------------------------------------------------------------------------
1 | Public Class Student
2 | Public Id As Integer
3 | Public Name As String
4 | Public Age As Integer
5 | End Class
6 |
--------------------------------------------------------------------------------
/RazorPages1/Data/Student.vb:
--------------------------------------------------------------------------------
1 | Public Class Student
2 | Public Id As Integer
3 | Public Name As String
4 | Public Age As Integer
5 | Public Grade As Integer
6 | End Class
7 |
--------------------------------------------------------------------------------
/WebApp1/Models/Student.vb:
--------------------------------------------------------------------------------
1 | Public Class Student
2 | Public Id As Integer
3 | Public Name As String
4 | Public Age As Integer
5 | Public Grade As Integer
6 | End Class
7 |
--------------------------------------------------------------------------------
/WebApp1/Views/Home/Privacy.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewData["Title"] = "Privacy Policy";
3 | }
4 |
@ViewData["Title"]
5 |
6 |
Use this page to detail your site's privacy policy.
19 | Swapping to the Development environment displays detailed information about the error that occurred.
20 |
21 |
22 | The Development environment shouldn't be enabled for deployed applications.
23 | It can result in displaying sensitive information from exceptions to end users.
24 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development
25 | and restarting the app.
26 |
18 | Swapping to Development environment will display more detailed information about the error that occurred.
19 |
20 |
21 | The Development environment shouldn't be enabled for deployed applications.
22 | It can result in displaying sensitive information from exceptions to end users.
23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development
24 | and restarting the app.
25 |
18 | Swapping to Development environment will display more detailed information about the error that occurred.
19 |
20 |
21 | The Development environment shouldn't be enabled for deployed applications.
22 | It can result in displaying sensitive information from exceptions to end users.
23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development
24 | and restarting the app.
25 |
26 |
--------------------------------------------------------------------------------
/WebApp1/Controllers/HomeController.vb:
--------------------------------------------------------------------------------
1 | Imports System
2 | Imports System.Collections.Generic
3 | Imports System.Diagnostics
4 | Imports System.Linq
5 | Imports System.Threading.Tasks
6 | Imports WebApp1.Models
7 | Imports Microsoft.AspNetCore.Mvc
8 |
9 | Namespace Controllers
10 | Public Class HomeController : Inherits Controller
11 |
12 |
13 | Public Function Index() As IActionResult
14 | Dim html = New IndexView(Students, ViewData).Html
15 | Return View(New Models.VbXml(html))
16 | End Function
17 |
18 | Public Function Privacy() As IActionResult
19 | Return View()
20 | End Function
21 |
22 |
23 | Public Function [Error]() As IActionResult
24 | Return View(New ErrorViewModel With {.RequestId = If(Activity.Current?.Id, HttpContext.TraceIdentifier)})
25 | End Function
26 | End Class
27 |
28 | End Namespace
--------------------------------------------------------------------------------
/VbRazor/VBRazorMvcViewOptionsSetup.vb:
--------------------------------------------------------------------------------
1 | Imports Microsoft.AspNetCore.Mvc
2 | Imports Microsoft.AspNetCore.Mvc.ViewEngines
3 | Imports Microsoft.Extensions.Options
4 |
5 | Public Class VBRazorMvcViewOptionsSetup
6 | Implements IConfigureOptions(Of MvcViewOptions)
7 |
8 |
9 | Private ReadOnly _VBRazorViewEngine As IViewEngine
10 | Public Sub New(ByVal VBRazorViewEngine As IViewEngine)
11 | If VBRazorViewEngine Is Nothing Then
12 | Throw New ArgumentNullException(NameOf(VBRazorViewEngine))
13 | End If
14 |
15 | _VBRazorViewEngine = VBRazorViewEngine
16 | End Sub
17 |
18 | Public Sub Configure(ByVal options As MvcViewOptions) Implements IConfigureOptions(Of MvcViewOptions).Configure
19 | If options Is Nothing Then
20 | Throw New ArgumentNullException(NameOf(options))
21 | End If
22 |
23 | options.ViewEngines.Add(_VBRazorViewEngine)
24 | End Sub
25 | End Class
26 |
--------------------------------------------------------------------------------
/RazorPages1/Pages/Shared/_CookieConsentPartial.cshtml:
--------------------------------------------------------------------------------
1 | @using Microsoft.AspNetCore.Http.Features
2 |
3 | @{
4 | var consentFeature = Context.Features.Get();
5 | var showBanner = !consentFeature?.CanTrack ?? false;
6 | var cookieString = consentFeature?.CreateConsentCookie();
7 | }
8 |
9 | @if (showBanner)
10 | {
11 |
12 | Use this space to summarize your privacy and cookie use policy. Learn More.
13 |
16 |
29 |
33 |
34 |
35 | End Function
36 |
37 | End Class
38 |
--------------------------------------------------------------------------------
/VBRazorSample/Views/Home/IndexView.vb:
--------------------------------------------------------------------------------
1 | Imports Microsoft.AspNetCore.Mvc.ModelBinding
2 | Imports VbRazor
3 |
4 | Public Class IndexView
5 | Implements IRazor
6 |
7 | Dim students As List(Of Student)
8 |
9 | Public Sub New(students As List(Of Student))
10 | Me.students = students
11 |
12 | End Sub
13 |
14 | Public Property ViewBag As Object Implements IRazor.ViewBag
15 |
16 | Public Property ModelState As ModelStateDictionary Implements IRazor.ModelState
17 |
18 | Public Function RenderView() As XElement Implements IRazor.RenderView
19 | Dim layout As New LayoutView(Razor(), ViewBag, ModelState)
20 | Return layout.Razor
21 | End Function
22 |
23 | Public Function Razor() As XElement Implements IRazor.Razor
24 | ViewBag.Title = "VB Razor Sample"
25 | Return _
26 |
27 |
Browse Students
28 |
Select from <%= students.Count() %> students:
29 |
30 | <%= (Iterator Function()
31 | For Each std In students
32 | Yield
<%= std.Name %>
33 | Next
34 | End Function)() %>
35 |
36 |
40 |
41 |
42 | End Function
43 | End Class
44 |
--------------------------------------------------------------------------------
/WebApp1/wwwroot/css/site.css:
--------------------------------------------------------------------------------
1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2 | for details on configuring this project to bundle and minify static web assets. */
3 |
4 | a.navbar-brand {
5 | white-space: normal;
6 | text-align: center;
7 | word-break: break-all;
8 | }
9 |
10 | /* Sticky footer styles
11 | -------------------------------------------------- */
12 | html {
13 | font-size: 14px;
14 | }
15 | @media (min-width: 768px) {
16 | html {
17 | font-size: 16px;
18 | }
19 | }
20 |
21 | .border-top {
22 | border-top: 1px solid #e5e5e5;
23 | }
24 | .border-bottom {
25 | border-bottom: 1px solid #e5e5e5;
26 | }
27 |
28 | .box-shadow {
29 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
30 | }
31 |
32 | button.accept-policy {
33 | font-size: 1rem;
34 | line-height: inherit;
35 | }
36 |
37 | /* Sticky footer styles
38 | -------------------------------------------------- */
39 | html {
40 | position: relative;
41 | min-height: 100%;
42 | }
43 |
44 | body {
45 | /* Margin bottom by footer height */
46 | margin-bottom: 60px;
47 | }
48 | .footer {
49 | position: absolute;
50 | bottom: 0;
51 | width: 100%;
52 | white-space: nowrap;
53 | /* Set the fixed height of the footer here */
54 | height: 60px;
55 | line-height: 60px; /* Vertically center the text there */
56 | }
57 |
--------------------------------------------------------------------------------
/RazorPages1/wwwroot/css/site.css:
--------------------------------------------------------------------------------
1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2 | for details on configuring this project to bundle and minify static web assets. */
3 |
4 | a.navbar-brand {
5 | white-space: normal;
6 | text-align: center;
7 | word-break: break-all;
8 | }
9 |
10 | /* Sticky footer styles
11 | -------------------------------------------------- */
12 | html {
13 | font-size: 14px;
14 | }
15 | @media (min-width: 768px) {
16 | html {
17 | font-size: 16px;
18 | }
19 | }
20 |
21 | .border-top {
22 | border-top: 1px solid #e5e5e5;
23 | }
24 | .border-bottom {
25 | border-bottom: 1px solid #e5e5e5;
26 | }
27 |
28 | .box-shadow {
29 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
30 | }
31 |
32 | button.accept-policy {
33 | font-size: 1rem;
34 | line-height: inherit;
35 | }
36 |
37 | /* Sticky footer styles
38 | -------------------------------------------------- */
39 | html {
40 | position: relative;
41 | min-height: 100%;
42 | }
43 |
44 | body {
45 | /* Margin bottom by footer height */
46 | margin-bottom: 60px;
47 | }
48 | .footer {
49 | position: absolute;
50 | bottom: 0;
51 | width: 100%;
52 | white-space: nowrap;
53 | /* Set the fixed height of the footer here */
54 | height: 60px;
55 | line-height: 60px; /* Vertically center the text there */
56 | }
57 |
--------------------------------------------------------------------------------
/VBRazorSample/wwwroot/css/site.css:
--------------------------------------------------------------------------------
1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2 | for details on configuring this project to bundle and minify static web assets. */
3 |
4 | a.navbar-brand {
5 | white-space: normal;
6 | text-align: center;
7 | word-break: break-all;
8 | }
9 |
10 | /* Sticky footer styles
11 | -------------------------------------------------- */
12 | html {
13 | font-size: 14px;
14 | }
15 | @media (min-width: 768px) {
16 | html {
17 | font-size: 16px;
18 | }
19 | }
20 |
21 | .border-top {
22 | border-top: 1px solid #e5e5e5;
23 | }
24 | .border-bottom {
25 | border-bottom: 1px solid #e5e5e5;
26 | }
27 |
28 | .box-shadow {
29 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
30 | }
31 |
32 | button.accept-policy {
33 | font-size: 1rem;
34 | line-height: inherit;
35 | }
36 |
37 | /* Sticky footer styles
38 | -------------------------------------------------- */
39 | html {
40 | position: relative;
41 | min-height: 100%;
42 | }
43 |
44 | body {
45 | /* Margin bottom by footer height */
46 | margin-bottom: 60px;
47 | }
48 | .footer {
49 | position: absolute;
50 | bottom: 0;
51 | width: 100%;
52 | white-space: nowrap;
53 | /* Set the fixed height of the footer here */
54 | height: 60px;
55 | line-height: 60px; /* Vertically center the text there */
56 | }
57 |
--------------------------------------------------------------------------------
/VbRazor/PathHelper.vb:
--------------------------------------------------------------------------------
1 |
2 | Public NotInheritable Class PathHelper
3 |
4 | Private Sub New()
5 | End Sub
6 |
7 | Public Shared Function GetAbsolutePath(ByVal executingFilePath As String, ByVal pagePath As String) As String
8 | ' Path is not valid or a page name; no change required.
9 | If String.IsNullOrEmpty(pagePath) OrElse (Not IsRelativePath(pagePath)) Then
10 | Return pagePath
11 | End If
12 |
13 | If IsAbsolutePath(pagePath) Then
14 | ' An absolute path already; no change required.
15 | Return pagePath.Replace("~/", String.Empty)
16 | End If
17 |
18 | ' Given a relative path i.e. not yet application-relative (starting with "~/" or "/"), interpret
19 | ' path relative to currently-executing view, if any.
20 | If String.IsNullOrEmpty(executingFilePath) Then
21 | ' Not yet executing a view. Start in app root.
22 | Return $"/{pagePath}"
23 | End If
24 |
25 | ' Get directory name (including final slash) but do not use Path.GetDirectoryName() to preserve path
26 | ' normalization.
27 | Dim index = executingFilePath.LastIndexOf("/"c)
28 | Return executingFilePath.Substring(0, index + 1) & pagePath
29 | End Function
30 |
31 | Public Shared Function IsAbsolutePath(name As String) As Boolean
32 | Return name.StartsWith("~/") OrElse name.StartsWith("/")
33 | End Function
34 |
35 | ' Though ./ViewName looks like a relative path, framework searches for that view using view locations.
36 | Public Shared Function IsRelativePath(name As String) As Boolean
37 | Return Not IsAbsolutePath(name)
38 | End Function
39 | End Class
40 |
--------------------------------------------------------------------------------
/RazorPages1/Startup.vb:
--------------------------------------------------------------------------------
1 | Imports Microsoft.AspNetCore.Builder
2 | Imports Microsoft.AspNetCore.Hosting
3 | Imports Microsoft.AspNetCore.Http
4 | Imports Microsoft.AspNetCore.HttpsPolicy
5 | Imports Microsoft.AspNetCore.Mvc
6 | Imports Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
7 | Imports Microsoft.Extensions.Configuration
8 | Imports Microsoft.Extensions.DependencyInjection
9 | Imports Microsoft.Extensions.Hosting
10 |
11 | Public Class Startup
12 | Public Sub New(configuration As IConfiguration)
13 | configuration = configuration
14 | End Sub
15 |
16 | Public ReadOnly Property Configuration As IConfiguration
17 |
18 | ' This method gets called by the runtime. Use this method to add services to the container.
19 | Public Sub ConfigureServices(services As IServiceCollection)
20 | services.Configure(Of CookiePolicyOptions)(
21 | Sub(options)
22 | ' This lambda determines whether user consent for non-essential cookies Is needed for a given request.
23 | options.CheckConsentNeeded = Function(context) True
24 | options.MinimumSameSitePolicy = SameSiteMode.None
25 | End Sub)
26 |
27 | services.AddMvc().AddRazorRuntimeCompilation()
28 | services.AddMvc().AddNewtonsoftJson()
29 |
30 | End Sub
31 |
32 | ' This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
33 | Public Sub Configure(app As IApplicationBuilder, env As IWebHostEnvironment)
34 |
35 | If (env.IsDevelopment()) Then
36 | app.UseDeveloperExceptionPage()
37 | Else
38 | app.UseExceptionHandler("/Home/Error")
39 | ' The default HSTS value Is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
40 | app.UseHsts()
41 | End If
42 |
43 | app.UseHttpsRedirection()
44 | app.UseStaticFiles()
45 |
46 | app.UseRouting(Sub(routes) routes.MapRazorPages())
47 |
48 | app.UseCookiePolicy()
49 | app.UseAuthorization()
50 |
51 | 'Vazor.VazorViewMapper.AddStatic(New LayoutView())
52 |
53 | End Sub
54 | End Class
--------------------------------------------------------------------------------
/WebApp1/Startup.vb:
--------------------------------------------------------------------------------
1 | Imports Microsoft.AspNetCore.Builder
2 | Imports Microsoft.AspNetCore.Hosting
3 | Imports Microsoft.AspNetCore.Http
4 | Imports Microsoft.AspNetCore.HttpsPolicy
5 | Imports Microsoft.AspNetCore.Mvc
6 | Imports Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
7 | Imports Microsoft.Extensions.Configuration
8 | Imports Microsoft.Extensions.DependencyInjection
9 | Imports Microsoft.Extensions.Hosting
10 |
11 | Public Class Startup
12 | Public Sub New(configuration As IConfiguration)
13 | configuration = configuration
14 | End Sub
15 |
16 | Public ReadOnly Property Configuration As IConfiguration
17 |
18 | ' This method gets called by the runtime. Use this method to add services to the container.
19 | Public Sub ConfigureServices(services As IServiceCollection)
20 | services.Configure(Of CookiePolicyOptions)(
21 | Sub(options)
22 | ' This lambda determines whether user consent for non-essential cookies Is needed for a given request.
23 | options.CheckConsentNeeded = Function(context) True
24 | options.MinimumSameSitePolicy = SameSiteMode.None
25 | End Sub)
26 |
27 | services.AddMvc().AddRazorRuntimeCompilation()
28 | services.AddMvc().AddNewtonsoftJson()
29 |
30 | End Sub
31 |
32 | ' This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
33 | Public Sub Configure(app As IApplicationBuilder, env As IWebHostEnvironment)
34 |
35 | If (env.IsDevelopment()) Then
36 | app.UseDeveloperExceptionPage()
37 | Else
38 | app.UseExceptionHandler("/Home/Error")
39 | ' The default HSTS value Is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
40 | app.UseHsts()
41 | End If
42 |
43 | app.UseHttpsRedirection()
44 | app.UseStaticFiles()
45 |
46 | app.UseRouting(
47 | Sub(routes)
48 | routes.MapControllerRoute(
49 | name:="default",
50 | template:="{controller=Home}/{action=Index}/{id?}")
51 | routes.MapRazorPages()
52 | End Sub)
53 |
54 | app.UseCookiePolicy()
55 | app.UseAuthorization()
56 |
57 |
58 | End Sub
59 | End Class
--------------------------------------------------------------------------------
/VbRazor/VBRazorViewEngine.vb:
--------------------------------------------------------------------------------
1 | Imports System.IO
2 | Imports Microsoft.AspNetCore.Mvc
3 | Imports Microsoft.AspNetCore.Mvc.ViewEngines
4 |
5 | Public Class VBRazorViewEngine
6 | Implements IViewEngine
7 |
8 | Public Function GetNormalizedRouteValue(ByVal context As ActionContext, ByVal key As String) As String
9 | If context Is Nothing Then
10 | Throw New ArgumentNullException(NameOf(context))
11 | End If
12 |
13 | If key Is Nothing Then
14 | Throw New ArgumentNullException(NameOf(key))
15 | End If
16 |
17 | Dim routeValue As Object
18 | If Not context.RouteData.Values.TryGetValue(key, routeValue) Then
19 | Return Nothing
20 | End If
21 |
22 | Dim normalizedValue As String = Nothing
23 | Dim value As String
24 | If context.ActionDescriptor.RouteValues.TryGetValue(key, value) AndAlso (Not String.IsNullOrEmpty(value)) Then
25 | normalizedValue = value
26 | End If
27 |
28 | Dim stringRouteValue = routeValue?.ToString()
29 | Return If(String.Equals(normalizedValue, stringRouteValue, StringComparison.OrdinalIgnoreCase), normalizedValue, stringRouteValue)
30 | End Function
31 |
32 | Public Function FindView(context As ActionContext, viewName As String, isMainPage As Boolean) As ViewEngineResult Implements IViewEngine.FindView
33 | Dim controllerName = GetNormalizedRouteValue(context, "controller")
34 | Dim areaName = GetNormalizedRouteValue(context, "area")
35 |
36 | Dim checkedLocations = New List(Of String)()
37 | Return ViewEngineResult.Found("Default", New VBRazorView())
38 |
39 | End Function
40 |
41 | Private Function IViewEngine_GetView(executingFilePath As String, viewPath As String, isMainPage As Boolean) As ViewEngineResult Implements IViewEngine.GetView
42 | Dim applicationRelativePath = PathHelper.GetAbsolutePath(executingFilePath, viewPath)
43 |
44 | If Not PathHelper.IsAbsolutePath(viewPath) Then
45 | ' Not a path this method can handle.
46 | Return ViewEngineResult.NotFound(applicationRelativePath, Enumerable.Empty(Of String)())
47 | End If
48 |
49 | ' ReSharper disable once Mvc.ViewNotResolved
50 | Return ViewEngineResult.Found("Default", New VBRazorView())
51 |
52 | End Function
53 | End Class
54 |
--------------------------------------------------------------------------------
/VBRazorSample/Startup.vb:
--------------------------------------------------------------------------------
1 | Imports System
2 | Imports System.Collections.Generic
3 | Imports System.Linq
4 | Imports System.Threading.Tasks
5 | Imports Microsoft.AspNetCore.Builder
6 | Imports Microsoft.AspNetCore.Hosting
7 | Imports Microsoft.AspNetCore.Http
8 | Imports Microsoft.AspNetCore.HttpsPolicy
9 | Imports Microsoft.AspNetCore.Mvc
10 | Imports Microsoft.AspNetCore.Mvc.ViewEngines
11 | Imports Microsoft.Extensions.Configuration
12 | Imports Microsoft.Extensions.DependencyInjection
13 | Imports Microsoft.Extensions.Options
14 |
15 | Public Class Startup
16 |
17 | Public Sub New(ByVal configuration As IConfiguration)
18 |
19 | Me.Configuration = configuration
20 | End Sub
21 |
22 | Public ReadOnly Property Configuration() As IConfiguration
23 |
24 | ' This method gets called by the runtime. Use this method to add services to the container.
25 | Public Sub ConfigureServices(ByVal services As IServiceCollection)
26 |
27 | services.Configure(Of CookiePolicyOptions)(
28 | Sub(options)
29 | ' This lambda determines whether user consent for non-essential cookies is needed for a given request.
30 | options.CheckConsentNeeded = Function(context) True
31 | options.MinimumSameSitePolicy = SameSiteMode.None
32 | End Sub)
33 |
34 | services.AddTransient(Of IConfigureOptions(Of MvcViewOptions), VBRazor.VBRazorMvcViewOptionsSetup)()
35 | services.AddSingleton(Of IViewEngine, VBRazor.VBRazorViewEngine)()
36 |
37 |
38 | services.AddMvc().AddNewtonsoftJson()
39 |
40 | End Sub
41 |
42 | ' This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
43 | Public Sub Configure(ByVal app As IApplicationBuilder, ByVal env As IHostingEnvironment)
44 |
45 | If env.IsDevelopment() Then
46 | app.UseDeveloperExceptionPage()
47 |
48 | Else
49 | app.UseExceptionHandler("/Home/Error")
50 | ' The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
51 | app.UseHsts()
52 | End If
53 |
54 | app.UseHttpsRedirection()
55 |
56 | app.UseStaticFiles()
57 |
58 | app.UseRouting(
59 | Sub(routes)
60 | routes.MapControllerRoute(
61 | name:="default",
62 | template:="{controller=Home}/{action=Index}/{id?}")
63 | routes.MapRazorPages()
64 | End Sub)
65 |
66 | app.UseCookiePolicy()
67 |
68 | app.UseAuthorization()
69 |
70 | End Sub
71 |
72 | End Class
73 |
--------------------------------------------------------------------------------
/VB.NET MVC Core Sample.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.28705.295
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "WebApp1", "WebApp1\WebApp1.vbproj", "{9540656A-EB63-412E-AD30-343B15E7D1CA}"
7 | EndProject
8 | Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "RazorPages1", "RazorPages1\RazorPages1.vbproj", "{A1DAF3E6-FF95-487A-ADF5-2E40FF3B098F}"
9 | EndProject
10 | Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "VbRazor", "VbRazor\VbRazor.vbproj", "{14C11FFA-A0E8-43FF-BEB9-902D639F3E01}"
11 | EndProject
12 | Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "VBMvcSample", "VBRazorSample\VBMvcSample.vbproj", "{C8A77870-8506-4B89-AB3C-1125D6B0D44A}"
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Release|Any CPU = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {9540656A-EB63-412E-AD30-343B15E7D1CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {9540656A-EB63-412E-AD30-343B15E7D1CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {9540656A-EB63-412E-AD30-343B15E7D1CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {9540656A-EB63-412E-AD30-343B15E7D1CA}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {A1DAF3E6-FF95-487A-ADF5-2E40FF3B098F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {A1DAF3E6-FF95-487A-ADF5-2E40FF3B098F}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {A1DAF3E6-FF95-487A-ADF5-2E40FF3B098F}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {A1DAF3E6-FF95-487A-ADF5-2E40FF3B098F}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {14C11FFA-A0E8-43FF-BEB9-902D639F3E01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {14C11FFA-A0E8-43FF-BEB9-902D639F3E01}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {14C11FFA-A0E8-43FF-BEB9-902D639F3E01}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {14C11FFA-A0E8-43FF-BEB9-902D639F3E01}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {C8A77870-8506-4B89-AB3C-1125D6B0D44A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {C8A77870-8506-4B89-AB3C-1125D6B0D44A}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {C8A77870-8506-4B89-AB3C-1125D6B0D44A}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {C8A77870-8506-4B89-AB3C-1125D6B0D44A}.Release|Any CPU.Build.0 = Release|Any CPU
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | GlobalSection(ExtensibilityGlobals) = postSolution
41 | SolutionGuid = {870DAF7F-0F05-4BEC-BB8F-805DC6BF6ECE}
42 | EndGlobalSection
43 | EndGlobal
44 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Note:
2 | I use a better way in [Vazor](https://github.com/VBAndCs/Vazor) to make use of tag helpers and other Razor capabililties.
3 |
4 | This is a working VB.NET ASP.NET MVC Core Razor sample!
5 | I implemented a simple VBRazorViewEngine in the VbRazor project.
6 | To use VBRazorViewEngine in the web project:
7 | 1- Add a reference to VBRazor.dll
8 | 2- Added these two statements to the Startup.ConfigureServices method:
9 | ```VB.NET
10 | services.AddTransient(Of IConfigureOptions(Of MvcViewOptions), VBRazor.VBRazorMvcViewOptionsSetup)()
11 | services.AddSingleton(Of IViewEngine, VBRazor.VBRazorViewEngine)()
12 | ```
13 |
14 | 3- Creat a Razor Virew class:
15 | The VBRazor is just a VB class that implements the IVBRazor Interface:
16 | ```VB.NET
17 | Public Interface IVBRazor
18 | ReadOnly Property Razor As String
19 |
20 | End Interface
21 | ```
22 |
23 | The Razor property uses the xml literals to compose the HTML code and returns it as a string.. Example:
24 | ```VB.NET
25 | Imports VbRazor
26 |
27 | Public Class IndexView
28 | Implements IVBRazor
29 |
30 | Dim students As List(Of Student)
31 |
32 | Public Sub New(students As List(Of Student))
33 | Me.students = students
34 | End Sub
35 |
36 | Public ReadOnly Property Razor As String Implements IVBRazor.Razor
37 | Get
38 | Dim x =
39 |
Browse Students
40 |
Select from <%= students.Count() %> students:
41 |
42 | <%= (Iterator Function()
43 | For Each std In students
44 | Yield
<%= std.Name %>
45 | Next
46 | End Function)() %>
47 |
48 |
49 | Return x.ToString()
50 |
51 | End Get
52 | End Property
53 | End Class
54 | ```
55 |
56 | 4- To use the Razor View Class from the Controller:
57 | in the action method, pass an instance of the razor class to the View method, and pass the model data to its constructor:
58 | ```VB.NET
59 | Public Function Index() As IActionResult
60 | Return View(New IndexView(Students))
61 | End Function
62 | ```
63 |
64 | And that’s all!
65 | If you run the project, you will see the web page that VBRazor composed!.. In this example, it will be as in the image:
66 |
67 | 
68 |
69 |
70 | This was really easy, but needs more work, so I hope you start contribute to this project to make it a real productive tool!
71 | 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!
72 |
73 | The second thing to do, is to add intellisense support for html attributes in xml literals in VB!
74 |
75 | 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.
76 |
77 |
--------------------------------------------------------------------------------
/VBRazorSample/My Project/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
52 |
59 |
60 |
61 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/RazorPages1/Pages/Shared/_Layout.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | @ViewData["Title"] - RazorPages1
7 |
8 |
9 |
10 |
11 |
12 |
17 |
18 |
19 |
20 |
21 |
22 |
41 |
42 |