Reputation: 76
I've got an ASP.NET Core MVC Web App, and one of my Views has too much HTML, causing it to look messy and difficult to find stuff, is there a way to extract some of the HTML (for example a certain div) to a different .cshtml file that I can then include in the View?
Upvotes: 0
Views: 244
Reputation: 18189
Here is a partial view sample:
Shared/partial1.cshtml:
<h1>partial1</h1>
Test.cshtml:
<partial name="partial1" />
Or:
@await Html.PartialAsync("partial1.cshtml")
result:
You can also use View Component,here is an official doc.
Upvotes: 1