BrownPony
BrownPony

Reputation: 633

How to get to partial views in ASP.NET Core 3.0

I have a Core 3.0 project using Areas and in an Area view I am trying to reference a partial view from the main project Views>Shared folder.

Project>Views>Shared>_layout_partial.cshtml << desired view partial.

Project>Areas>MyArea>Views>Index.cshtml << this view is trying to access the partial described above.

<div>
    <div class="container-fluid">        
        <partial name= "~/Views/Shared/_layout_partial1.cshtml"/>   
        <partial name="~Views/Shared/_layout_partial2.cshtml"/>
        <partial name="~/Views/Shared/_layout_partial3.cshtml"/>
    </div><!-- container -->
</div>

This works fine when the main view is in Project>Views>Home>Index.cshtml but the partial view is not recognized all when the main view is in an area and no warnings or errors.

Is it possible to access this partial view from an area or do I have to do serious could duplication.

Upvotes: 1

Views: 1482

Answers (1)

Muhammad Kamran Aslam
Muhammad Kamran Aslam

Reputation: 658

For partial, it is using Microsoft.AspNetCore.Mvc.TagHelpers, here are two options for you:

Change to use

@await Html.PartialAsync("/Views/Shared/_layout_partial1.cshtml")

If you prefer partial tag, you need to reference the Microsoft.AspNetCore.Mvc.TagHelpers by copying _ViewImports.cshtml from Views Folder to your Areas Folder

Upvotes: 2

Related Questions