Results 1 to 1 of 1

Thread: Create ASP.NET Core apps with VB.NET and design views and pages with VB.NET too!

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2020
    Posts
    49

    Create ASP.NET Core apps with VB.NET and design views and pages with VB.NET too!

    Hi all.
    Do you now that you can fully write ASP.NET Core 6 apps with VB .NET in VS2019 and VS2022?
    All you need to do is downloading this VS Extension (or use the VS.NET Extension Manager to install it directly):
    https://marketplace.visualstudio.com...ernVBNET.Vazor
    and double-click VazorEx.vsix to setup these Vazor templates:
    1. A Vazor project template for ASP.NET MVC Core 6.0 .
    2. A Vazor project template for ASP.NET Web Pages Core 6.0 .
    3. A VazorView item template to add a new vazor view (.vazor and .vbxml.vb files) to the MVC project.
    4. A VazorPage item template to add a new vazor page (.cshtml, .cshtml.vb, and .vbxml.vb files) to the Razor Pages project.
    After installation:
    open VS.Net and create a new project. In the search box, write Vazor, and choose one of the 2 vazor project templates.
    In the project created, right-click a folder in solution explorer and select Add/New Item.
    From the dialogue box select VazorView (if this is an MVC project) or VazorPage (if this is a Razor Pages project).
    You can easily understand the structure of the Vazor view/page, as it uses VB.NET XML literals to compose the vbHtml code, such as:
    Code:
    Partial Public Class IndexView
        Public overrides Function GetVbXml(view As IndexView) As XElement
            Return _
     _
            <vbxml>
                <h3> Browse Students</h3>
                <p>Select from <%= view.Students.Count() %> students:</p>
                <ul>
                    <%= (Iterator Function()
                             For Each std In view.Students
                                 Yield <li><%= std.Name %></li>
                             Next
                         End Function)() %>
                </ul>
                <p>Students details:</p>
                <ul>
                    <li ForEach="m">
                    Id: <m.Id/><br/>
                    Name: <m.Name/><br/>
                        <p>Grade: <m.Grade/></p>
                    </li>
                </ul>
                <script>
                     var x = 5;
                     document.writeln("students count = <%= view.Students.Count() %>");
            </script>
            </vbxml>
    
        End Function
    
    End Class
    VazorEx also installs an Html5 CompletionProvider. It provides Html5 auto completion in VB XML literals: untitled1 The auto completion is enabled only when XML root is <vbxml> or <zml>:
    Code:
    Dim x = <vbxml>
            <!—auto completion for HTML 5 is available here -->
       </vbxml>
    You can write <% and press Ctrl+space to get this block written for you:
    Code:
        <%= (Function()
                  Return < />
               End Function)( )%>
    where you can use conditions or any other vb code to return an html node. And you can write <( and press Ctrl+space to get this block written for you:
    Code:
         <%= (Iterator Function()
                  For Each item In Collection
                       Yield <p><%= item %></p>
                  Next
               End Function)( ) %>
    where you can modify it to iterate through your collection and yield an html node based on each item in the collection, like filling a list with elements.

    For more details, see the readme:
    https://github.com/VBAndCs/Vazor/blob/master/README.md

    And here is also the source code of ShopOnWeb_VB.NET app:
    https://github.com/VBAndCs/eShopOnWeb_VB.NET
    which is the VB.NET version of the Microsoft full web sample eShopOnWeb
    but it is still uses ASP.NET Core 3.1. I will update it to ASP.NET Core 7 directly when it is released.
    I hope you find this info helpful, and start creating your web applications targeting ASP.NET Core using VB.NET and Vazor.
    Have fun
    Last edited by M.Hamdy; Sep 19th, 2022 at 04:54 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width