How to Use Blazor Components in ASP.NET Core MVC?

Sdílet
Vložit
  • čas přidán 15. 06. 2024
  • In this video, I show how to use Blazor components in an existing ASP.NET Core MVC application.
    00:00 Introduction
    00:27 The ASP.NET Core MVC Application
    00:52 Adding a Blazor Component
    01:43 Integrating a Blazor Component in an MVC Application
    02:38 Configuring an MVC Application for Blazor Server Interactivity
    03:39 Adding the _Import.razor File
    04:13 The Motivation
    04:58 Sharing Components using a Razor Class Library
    06:04 Using Blazor WebAssembly instead of Blazor Server
    09:54 Blazor Server vs. Blazor WebAssembly
    10:52 Conclusion
    🔥 C#/.NET Bootcamp: The Fundamentals & more (Code FRIENDS10 for 10% OFF)*
    claudiobernasconi.ch/dotnet-c...
    📓 MVC Blazor WebAssembly Code (GitHub):
    github.com/claudiobernasconi/...
    📓 MVC Blazor Server Code (GitHub):
    github.com/claudiobernasconi/...
    📌 .NET Developer Roadmap
    claudiobernasconi.ch/learn-do...
    📌 CZcams Playlists:
    The FREE Blazor Crash Course: • The FREE Blazor Crash ...
    Blazor: • Blazor
    ✅ SUBSCRIBE FOR MORE VIDEOS
    Subscribe: 🔔 claudiobernasconi.ch/Subscribe
    🚀 CONNECT & SUPPORT
    Twitter: / chbernasconic
    Blog: claudiobernasconi.ch
    Newsletter: claudiobernasconi.ch/newsletter
    * Affiliate Link: I earn a small commission at no additional cost
  • Věda a technologie

Komentáře • 23

  • @thibaultdolley734
    @thibaultdolley734 Před 17 dny

    Thank you for providing the github repository

  • @timmy334
    @timmy334 Před 3 měsíci +1

    This video provides the exact answers I needed! Thank you!

  • @THEArenaVD
    @THEArenaVD Před 2 měsíci

    Hey im trying to pass in a complex Object List in my razor component and when running my application I get Blazor server error usung chrome. Would you habe any idea as to why this is occurring?

  • @nezqwe4818
    @nezqwe4818 Před 4 měsíci

    Hi, I tried doing this with but when it hit the page. the generated value got ran twice by itself.
    For example, I hit the page the shown var was 22 then a few miliseconds it changed to 67. How do I prevent it from running again?
    I'm on .net 8.0.1

    • @ClaudioBernasconi
      @ClaudioBernasconi  Před 4 měsíci

      It depends on how you initialize the value. OnInitialiezed or OnInizializedAsync are good locations. Hard to tell your issue without seeing your code.

    • @nezqwe4818
      @nezqwe4818 Před 4 měsíci +1

      @@ClaudioBernasconi Ah, figured it out. It was prerender. I need to change render mode to render-mode="WebAssembly"

  • @maxalbrecht9913
    @maxalbrecht9913 Před 4 měsíci

    Hi, I am up to 3:30, but when I click the "Generate" button, the number does not change

    • @ClaudioBernasconi
      @ClaudioBernasconi  Před 4 měsíci

      That is not okay. However, it's hard to help you like that, I'm sorry. I hope you'll find a solution.

    • @ItsBabywise
      @ItsBabywise Před 2 měsíci

      Did you ever fix this issue? This seems to be my problem with every tutorial
      EDIT: The reason you get this issue is because your _Imports.razor does not yet exist if you're following along at 3:32... if u look closely, _Imports.razor appears on the right side in the video but its not talked about until afterwards which might be where your confusion comes from, once you add this file it will update

  • @ndasss9563
    @ndasss9563 Před 5 měsíci

    Does this work on .net 7 as well ? Sry im new..

    • @ClaudioBernasconi
      @ClaudioBernasconi  Před 5 měsíci

      Thanks for your question, and welcome. Yes, it should also work on .NET 7.

  • @leonardohidrovo4729
    @leonardohidrovo4729 Před 5 měsíci

    Using Sessions in a MVC core application, how to use the user session values in a Blazor component inside MVC view?

    • @ClaudioBernasconi
      @ClaudioBernasconi  Před 5 měsíci

      Great question. I'm not familiar with how Sessions work in MVC. However, that shouldn't be an issue. The concept is simple. You have to provide every information you want to use inside a Blazor component as an argument.
      There are more advanced concepts but I would keep it simple and provide the information from the Session as an argument (parameter) to the Blazor component.
      Say you want to use the username, you add a parameter using the [Parameter] attribute on the Blazor component and then provide it when you use the component.

    • @leonardohidrovo4729
      @leonardohidrovo4729 Před 5 měsíci

      @@ClaudioBernasconi thanks for the response. In my case I would like to use some existing mvc services (scope implementation) that uses IhttpcontextAccesor to get de user session values and retrieve information from database. However I saw in the Microsoft documentation that is not recommend to use the HttpContext in blazor server

  • @10Totti
    @10Totti Před 5 měsíci +1

    Thanks, but it wouldn't be easier to use Blazor Custom Elements