Use Blazor C# UI in .cshtml files? RRS feed

  • Question

  • User2110873642 posted

    can i only use 'Blazor UI C#' in .razor files, or can i also use it in .cshtml files?

    when i copy @code {} to a .cshtml file, it shows errors.

    i have the need to use it in layout pages.

    Monday, July 20, 2020 3:49 PM


All replies

  • User-821857111 posted

    Are you trying to use Blazor UI C#  in a n MVC layout page? If so, that's not supported. As I said in another of your threads, Blazor and MVC are not intended to be used together.

    Monday, July 20, 2020 4:25 PM
  • User2110873642 posted

    i know, i learned that from you. so i decided not to use MVC.

    i made  a Blazor project, and now i want to learn to use layouts, and nested layouts.

    can i use Blazor UI in cshtml?

    Monday, July 20, 2020 8:30 PM
  • User-821857111 posted

    Well, yes you can. In earlier previews of Blazor, razor components used cshtml files, but this was replaced by razor files. There is an MSBuild property setting that enables you to use cshtml files, but it is purely intended for backward compatibility. There is no benefit to using .cshtml files in a new Blazor app.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 21, 2020 4:15 AM