Use CreateRouteValues for creation routes (#8241)

Fixes #8238
This commit is contained in:
MarcoViglione-Laser
2019-07-25 21:10:34 +02:00
committed by Sébastien Ros
parent 8ca5351872
commit b6a4ef609d
2 changed files with 43 additions and 7 deletions

View File

@@ -1,5 +1,26 @@
@{ Layout.Title = T("Create New Content").ToString(); }
@using Orchard;
@using Orchard.ContentManagement;
@using Orchard.Core.Contents;
@{
IOrchardServices _orchardServices;
WorkContext.TryResolve<IOrchardServices>(out _orchardServices);
Layout.Title = T("Create New Content");
}
@foreach (var type in Model.ContentTypes) {
<p>@Html.ActionLink((string)type.DisplayName, "Create", new { Area = "Contents", Id = (string)type.Name, ContainerId = Model.ContainerId, ReturnUrl = Request.QueryString["ReturnUrl"] })</p>
var content = _orchardServices.ContentManager.New(type.Name);
if (Authorizer.Authorize(Permissions.CreateContent, content)) {
ContentItemMetadata metadata = _orchardServices.ContentManager.GetItemMetadata(content);
RouteValueDictionary createRouteValues = metadata.CreateRouteValues;
createRouteValues.Add("ContainerId", Model.ContainerId);
createRouteValues.Add("ReturnUrl", Request.QueryString["ReturnUrl"]);
var url = Url.RouteUrl(createRouteValues);
<p><a href="@url">@type.DisplayName</a></p>
}
}

View File

@@ -1,8 +1,13 @@
@using Orchard.Core.Contents;
@using Orchard;
@using Orchard.ContentManagement;
@using Orchard.Core.Contents;
@using Orchard.Core.Contents.ViewModels;
@using Orchard.Security;
@using Orchard.Security.Permissions;
@{
IOrchardServices _orchardServices;
WorkContext.TryResolve<IOrchardServices>(out _orchardServices);
var typeDisplayName = Model.TypeDisplayName;
var pageTitle = T("Manage Content");
var createLinkText = T("Create New Content");
@@ -28,7 +33,17 @@
}
@if (showCreateContentButton) {
<div class="manage">
@Html.ActionLink(createLinkText.Text, "Create", new { Area = "Contents", Id = (string)Model.Options.SelectedFilter }, new { @class = "button primaryAction" })
@{
if (!String.IsNullOrWhiteSpace((string)Model.Options.SelectedFilter)) {
var content = _orchardServices.ContentManager.New(Model.Options.SelectedFilter);
ContentItemMetadata metadata = _orchardServices.ContentManager.GetItemMetadata(content);
var url = Url.RouteUrl(metadata.CreateRouteValues);
<a class="button primaryAction" href="@url">@createLinkText.Text</a>
} else {
@Html.ActionLink(createLinkText.Text, "Create", new { Area = "Contents", Id = (string)Model.Options.SelectedFilter }, new { @class = "button primaryAction" });
}
}
</div>
}
@using (Html.BeginFormAntiForgeryPost()) {