Это видео недоступно.
Сожалеем об этом.

THIS is how you use Partial Views in ASP.NET Core 6

Поделиться
HTML-код
  • Опубликовано: 14 авг 2024
  • 🚀 C# Progress Academy - Become a senior C# developer: academy.tutori...
    Here are the LINKS btw!
    · Bootstrap reference page: getbootstrap.c...
    · Check out the C# Masterclass: bit.ly/38xC6WW
    · FREE C# Download 9 MUST have .NET Developer tools: page.tutorials...
    We´ll make sure to make a Developer out of you In no time!
    ☕ You can also support us now by buying us a coffee! ☕ www.buymeacoff...
    And we promise to create more cool content for you!
    Discover how to use partial views to break up large markup files and reduce the duplication of common markup across web pages in ASP.NET Core apps.
    A partial view is a Razor markup file (.cshtml) without an @page directive that renders HTML output within another markup file's rendered output.
    The term partial view is used when developing either an MVC app, where markup files are called views, or a Razor Pages app, where markup files are called pages. This topic generically refers to MVC views and Razor Pages pages as markup files.
    When to use partial views
    Partial views are an effective way to:
    Break up large markup files into smaller components.
    In a large, complex markup file composed of several logical pieces, there's an advantage to working with each piece isolated into a partial view. The code in the markup file is manageable because the markup only contains the overall page structure and references to partial views.
    Reduce the duplication of common markup content across markup files.
    When the same markup elements are used across markup files, a partial view removes the duplication of markup content into one partial view file. When the markup is changed in the partial view, it updates the rendered output of the markup files that use the partial view.
    Partial views shouldn't be used to maintain common layout elements. Common layout elements should be specified in _Layout.cshtml files.
    Don't use a partial view where complex rendering logic or code execution is required to render the markup. Instead of a partial view, use a view component.
    Declare partial views
    A partial view is a .cshtml markup file without an @page directive maintained within the Views folder (MVC) or Pages folder (Razor Pages).
    In ASP.NET Core MVC, a controller's ViewResult is capable of returning either a view or a partial view. In Razor Pages, a PageModel can return a partial view represented as a PartialViewResult object. Referencing and rendering partial views is described in the Reference a partial view section.
    Unlike MVC view or page rendering, a partial view doesn't run _ViewStart.cshtml. For more information on _ViewStart.cshtml, see Layout in ASP.NET Core.
    Partial view file names often begin with an underscore (_). This naming convention isn't required, but it helps to visually differentiate partial views from views and pages.
    Note: A Razor section defined in a partial view is invisible to parent markup files. The section is only visible to the partial view in which it's defined.
    Check out the video to learn more!
    TIMESTAMPS:
    00:00 - 02:30 Why you should use Partial Views
    02:30 - 03:17 ASP.NET Core Challenge
    03:17 - 04:31 Project explaination
    04:31 - 07:29 Create Partial View and setup an Action
    07:29 - 09:31 Loading the Partial View using jQuery
    09:31 - 10:05 Don't miss that
    TAGS:
    partial,views,partial views,asp,net,core,asp net core,mvc,model view controller,asp.net core tutorial,c# asp.net core,.net 6,.net core 6,learn asp.net development,asp views,asp view,asp.net core view,asp partial,asp.net core partial,asp.net core partial view,asp.net core partial views,asp.net core shared,asp.net shared,backend development,learn asp.net core,programming,razor,view,Partial views in ASP.NET Core,partial views asp net,asp net,dot net
    tutorialsEU offers you free video tutorials about programming and development for complete beginners up to experienced programmers.
    This includes C#, Unity, Python, Android, Kotlin, Machine Learning, etc.
    Stay tuned and subscribe to tutorialsEU: goo.gl/rBFh3x
    Android: / @tutorialseuandroid
    C#: / @tutorialseuc
    Unity: / @tutorialseuunity
    Facebook: / tutorialseu-1093802040...
    LinkedIn: / tutorialseu
    Discord: / discord

Комментарии • 29

  • @tutorialsEUC
    @tutorialsEUC  2 года назад +2

    🚀C# Progress Academy - Become a senior C# developer: academy.tutorials.eu/p/csharp-progress-academy

    • @andread4721
      @andread4721 2 года назад

      Two questions: When will it start? Will you fill my mailbox with tons of spam?

  • @MrTonyradford
    @MrTonyradford 3 месяца назад

    Thanks for this - it's a very useful technique and saves passing the partial model data into the view.

  • @user-zb2pf9ow1j
    @user-zb2pf9ow1j 2 года назад +7

    Let me ask you a question. Why didn't you use
    @await Html.Partial Async("_BlogArticles", blogentries)

    • @tutorialsEUC
      @tutorialsEUC  2 года назад +3

      Hi, thanks for adding that nice helper function. Your way definately works too but from my side of experience in MVC most stuff (especially when it comes to datatable etc.) gets rendered (even partial views) by using the jquery approach to manage when stuff is loaded. My approach allows you to run code after the partial view has loaded (and you will do that alot!).
      Greets,
      Jannick :-)

  • @dyaaCoding
    @dyaaCoding Год назад +1

    can this be done in Razor pages . I have a model i created a scaffold from. I now have a folder in my Pages called Categories and it has Create, Index ,delete, details cshtml and cshtml.cs. i want my main Pages/Index.cshtml to render the Pages/Categories/Index.Cshtml in my main Index. While maintaining the ability to press the create button and actually add a new iterm.

  • @acatij
    @acatij 3 месяца назад

    Can we load a partialView with different data, example for home 6 articles and for archivo only 2?

  • @dinoma2095
    @dinoma2095 5 месяцев назад

    Hi, im working on my own project with View transitions API, has someone combined partialViews with it?,
    Good video by the way.

  • @acatij
    @acatij 3 месяца назад

    Can this be used to create some common controls, like a dropdwons that are used multiple times over a proyect?

    • @MrTonyradford
      @MrTonyradford 3 месяца назад

      I think this approach could be used for any control in a partial, if you pass the data formatted correctly into the partial.

  • @hannahbandana88
    @hannahbandana88 Год назад

    I cant find the link too the asp net 5 day challenge?

  • @woquendoG
    @woquendoG Год назад

    hi, how to remove that partial?

  • @tanoryjakaperdana1419
    @tanoryjakaperdana1419 10 месяцев назад +3

    So its jquery

  • @harrynewman1744
    @harrynewman1744 2 года назад +1

    Also for me this method returns error 500

  • @siddhantpanda5455
    @siddhantpanda5455 Год назад

    Is it possible to render in cstml insted of scripts tag

  • @abc-hl1pw
    @abc-hl1pw 2 года назад +1

    Greeat video thanks

  • @stijntempelaere8772
    @stijntempelaere8772 Год назад

    I was just wondering if you need to repeat the script part in every page you want to render the partial view? Is it possible to create a class instead and place it in the js file?

    • @FromRootsToRadicals_INTP
      @FromRootsToRadicals_INTP 8 месяцев назад

      It depends on your setup. Normally you want to consolidate scripts to the view they are needed. If you placed it outside then it would always be rendered without the partial. If you have multiple partials on one view that are all the same then obviously dont do that. You could then place in a render tag at the parent view when needed.

    • @FromRootsToRadicals_INTP
      @FromRootsToRadicals_INTP 8 месяцев назад +1

      But for scope purposes we like to place scripts of partial inside the partial.

  • @binodsharma112
    @binodsharma112 10 месяцев назад

    Nice, explain , I prefer using HTMX in partial .

  • @damianjankov3343
    @damianjankov3343 2 года назад

    Very nicely explained, thank you!

  • @gollumei
    @gollumei Год назад

    This is exactly why React is the best framework, so much easier than this mess.

  • @bojohannesen4352
    @bojohannesen4352 2 месяца назад

    Dumb thumbnail. Bad tutorial. No Bueno.

    • @nyx8026
      @nyx8026 Месяц назад

      Could you elaborate

    • @bojohannesen4352
      @bojohannesen4352 Месяц назад

      @@nyx8026 Not to you.

    • @nyx8026
      @nyx8026 Месяц назад

      @@bojohannesen4352 To whom then?