-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UE pass on Partial views doc (#7417)
Fixes #7322 **Changes** - Add Partial Tag Helper info (2.1+ only) - Simplify & improve sample app and update to 2.1 - Add **Additional resources** section - Apply Acrolinx suggestions - Introduce headings in **Reference a partial view** section [Internal Review Page](https://review.docs.microsoft.com/en-us/aspnet/core/mvc/views/partial?branch=pr-en-us-7417&view=aspnetcore-2.1)
- Loading branch information
1 parent
ca3da66
commit 9121516
Showing
80 changed files
with
24,228 additions
and
430 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 1 addition & 6 deletions
7
...sSample/Controllers/ArticlesController.cs → ...sSample/Controllers/ArticlesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
aspnetcore/mvc/views/partial/sample/PartialViewsSample/Controllers/HomeController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace PartialViewsSample.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
public IActionResult Discovery() => View(); | ||
|
||
public IActionResult Error() => View(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
aspnetcore/mvc/views/partial/sample/PartialViewsSample/PartialViewsSample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.App" /> | ||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
15 changes: 15 additions & 0 deletions
15
aspnetcore/mvc/views/partial/sample/PartialViewsSample/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
|
||
namespace PartialViewsSample | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) => | ||
CreateWebHostBuilder(args).Build().Run(); | ||
|
||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => | ||
WebHost.CreateDefaultBuilder(args) | ||
.UseStartup<Startup>(); | ||
} | ||
} |
33 changes: 16 additions & 17 deletions
33
.../sample/src/PartialViewsSample/Startup.cs → ...tial/sample/PartialViewsSample/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
aspnetcore/mvc/views/partial/sample/PartialViewsSample/Views/Articles/Read.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!-- <snippet_ReadPartialView> --> | ||
@model PartialViewsSample.ViewModels.Article | ||
|
||
<h2>@Model.Title</h2> | ||
@*Pass the author's name to Views\Shared\_AuthorPartial.cshtml*@ | ||
@await Html.PartialAsync("_AuthorPartial", Model.AuthorName) | ||
@Model.PublicationDate | ||
|
||
@*Loop over the Sections and pass in a section and additional ViewData | ||
to the strongly typed Views\Articles\_ArticleSection.cshtml partial view.*@ | ||
@{ | ||
var index = 0; | ||
|
||
@foreach (var section in Model.Sections) | ||
{ | ||
<!-- <snippet_PartialAsync> --> | ||
@await Html.PartialAsync("_ArticleSection", section, | ||
new ViewDataDictionary(this.ViewData) | ||
{ | ||
{ "index", index } | ||
}) | ||
<!-- </snippet_PartialAsync> --> | ||
|
||
index++; | ||
} | ||
} | ||
<!-- </snippet_ReadPartialView> --> |
2 changes: 1 addition & 1 deletion
2
...mple/Views/Articles/ArticleSection.cshtml → ...ple/Views/Articles/_ArticleSection.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
@using PartialViewsSample.ViewModels | ||
@model ArticleSection | ||
|
||
<h3>@Model.Title Index: @ViewData["index"] </h3> | ||
<h3>@Model.Title Index: @ViewData["index"]</h3> | ||
<div> | ||
@Model.Content | ||
</div> |
114 changes: 114 additions & 0 deletions
114
aspnetcore/mvc/views/partial/sample/PartialViewsSample/Views/Home/Discovery.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
@using PartialViewsSample.ViewModels | ||
@{ | ||
ViewData["Title"] = "Partial view discovery"; | ||
ViewData["index"] = 0; | ||
} | ||
|
||
<table class="table table-hover"> | ||
<caption>Asynchronous partial view discovery examples</caption> | ||
<thead> | ||
<tr> | ||
<th>Syntax</th> | ||
<th>Result</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<code> | ||
@Html.Raw(Html.Encode(@"<partial name=""_AuthorPartial"" />")) | ||
</code> | ||
<br /> | ||
<span class="badge">2.1+</span> | ||
</td> | ||
<td> | ||
<!-- <snippet_PartialTagHelper> --> | ||
<partial name="_AuthorPartial" /> | ||
<!-- </snippet_PartialTagHelper> --> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<code> | ||
@Html.Raw(Html.Encode(@"<partial name=""_AuthorPartial.cshtml"" />")) | ||
</code> | ||
<br /> | ||
<span class="badge">2.1+</span> | ||
</td> | ||
<td> | ||
<partial name="_AuthorPartial.cshtml" /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<code> | ||
@Html.Raw(Html.Encode(@"<partial name=""~/Views/Home/_AuthorPartial.cshtml"" />")) | ||
</code> | ||
<br /> | ||
<span class="badge">2.1+</span> | ||
</td> | ||
<td> | ||
<partial name="~/Views/Home/_AuthorPartial.cshtml" /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<code> | ||
@Html.Raw(Html.Encode(@"<partial name=""/Views/Home/_AuthorPartial.cshtml"" />")) | ||
</code> | ||
<br /> | ||
<span class="badge">2.1+</span> | ||
</td> | ||
<td> | ||
<partial name="/Views/Home/_AuthorPartial.cshtml" /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<code> | ||
@Html.Raw(Html.Encode(@"<partial name=""../Articles/_ArticleSection.cshtml"" model='new ArticleSection { Title=""Section 1"", Content=""Coming soon"" }' view-data=""ViewData"" />")) | ||
</code> | ||
<br /> | ||
<span class="badge">2.1+</span> | ||
</td> | ||
<td> | ||
<partial name="../Articles/_ArticleSection.cshtml" | ||
model='new ArticleSection { Title="Section 1", Content="Coming soon" }' | ||
view-data="ViewData" /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<code> | ||
@await Html.PartialAsync("_AuthorPartial") | ||
</code> | ||
</td> | ||
<td> | ||
<!-- <snippet_PartialAsync> --> | ||
@await Html.PartialAsync("_AuthorPartial") | ||
<!-- </snippet_PartialAsync> --> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<code> | ||
@{ await Html.RenderPartialAsync("_AuthorPartial"); } | ||
</code> | ||
</td> | ||
<td> | ||
<!-- <snippet_RenderPartialAsync> --> | ||
@{ | ||
await Html.RenderPartialAsync("_AuthorPartial"); | ||
} | ||
<!-- </snippet_RenderPartialAsync> --> | ||
</td> | ||
</tr> | ||
</tbody> | ||
<tfoot> | ||
<tr> | ||
<td colspan="2"> | ||
<span class="badge">2.1+</span> Supported in ASP.NET Core 2.1 or later | ||
</td> | ||
</tr> | ||
</tfoot> | ||
</table> |
4 changes: 4 additions & 0 deletions
4
aspnetcore/mvc/views/partial/sample/PartialViewsSample/Views/Home/_AuthorPartial.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div> | ||
<h3>Microsoft Docs</h3> | ||
Some bio info here. Follow us at <a href="https://twitter.com/docsmsft">twitter.com/docsmsft</a>. | ||
</div> |
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
aspnetcore/mvc/views/partial/sample/PartialViewsSample/Views/Shared/_AuthorPartial.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@model string | ||
<div> | ||
<h3>@Model</h3> | ||
This partial view came from /Views/Shared/_AuthorPartial.cshtml.<br /> | ||
</div> |
41 changes: 41 additions & 0 deletions
41
...ore/mvc/views/partial/sample/PartialViewsSample/Views/Shared/_CookieConsentPartial.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@using Microsoft.AspNetCore.Http.Features | ||
|
||
@{ | ||
var consentFeature = Context.Features.Get<ITrackingConsentFeature>(); | ||
var showBanner = !consentFeature?.CanTrack ?? false; | ||
var cookieString = consentFeature?.CreateConsentCookie(); | ||
} | ||
|
||
@if (showBanner) | ||
{ | ||
<nav id="cookieConsent" class="navbar navbar-default navbar-fixed-top" role="alert"> | ||
<div class="container"> | ||
<div class="navbar-header"> | ||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#cookieConsent .navbar-collapse"> | ||
<span class="sr-only">Toggle cookie consent banner</span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
</button> | ||
<span class="navbar-brand"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span></span> | ||
</div> | ||
<div class="collapse navbar-collapse"> | ||
<p class="navbar-text"> | ||
Use this space to summarize your privacy and cookie use policy. | ||
</p> | ||
<div class="navbar-right"> | ||
<a asp-page="/Privacy" class="btn btn-info navbar-btn">Learn More</a> | ||
<button type="button" class="btn btn-default navbar-btn" data-cookie-string="@cookieString">Accept</button> | ||
</div> | ||
</div> | ||
</div> | ||
</nav> | ||
<script> | ||
(function () { | ||
document.querySelector("#cookieConsent button[data-cookie-string]").addEventListener("click", function (el) { | ||
document.cookie = el.target.dataset.cookieString; | ||
document.querySelector("#cookieConsent").classList.add("hidden"); | ||
}, false); | ||
})(); | ||
</script> | ||
} |
Oops, something went wrong.