File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
src/Umbraco.Web.Common/Controllers Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,26 @@ protected IUmbracoContext UmbracoContext
53
53
/// </summary>
54
54
public virtual IActionResult Index ( ) => CurrentTemplate ( new ContentModel ( CurrentPage ) ) ;
55
55
56
+ /// <summary>
57
+ /// Gets an action result based on the template name found in the route values and a model.
58
+ /// </summary>
59
+ /// <typeparam name="T">The type of the model.</typeparam>
60
+ /// <param name="model">The model.</param>
61
+ /// <returns>The action result.</returns>
62
+ /// <remarks>
63
+ /// If the template found in the route values doesn't physically exist, Umbraco not found result is returned.
64
+ /// </remarks>
65
+ protected override IActionResult CurrentTemplate < T > ( T model )
66
+ {
67
+ if ( EnsurePhsyicalViewExists ( UmbracoRouteValues . TemplateName ) == false )
68
+ {
69
+ // no physical template file was found
70
+ return new PublishedContentNotFoundResult ( UmbracoContext ) ;
71
+ }
72
+
73
+ return View ( UmbracoRouteValues . TemplateName , model ) ;
74
+ }
75
+
56
76
/// <summary>
57
77
/// Before the controller executes we will handle redirects and not founds
58
78
/// </summary>
@@ -123,6 +143,6 @@ private PublishedContentNotFoundResult GetNoTemplateResult(IPublishedRequest pcr
123
143
{
124
144
return new PublishedContentNotFoundResult ( UmbracoContext ) ;
125
145
}
126
- }
146
+ }
127
147
}
128
148
}
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ protected virtual IPublishedContent CurrentPage
74
74
/// <param name="model">The model.</param>
75
75
/// <returns>The action result.</returns>
76
76
/// <exception cref="InvalidOperationException">If the template found in the route values doesn't physically exist and exception is thrown</exception>
77
- protected IActionResult CurrentTemplate < T > ( T model )
77
+ protected virtual IActionResult CurrentTemplate < T > ( T model )
78
78
{
79
79
if ( EnsurePhsyicalViewExists ( UmbracoRouteValues . TemplateName ) == false )
80
80
{
@@ -90,6 +90,13 @@ protected IActionResult CurrentTemplate<T>(T model)
90
90
/// <param name="template">The view name.</param>
91
91
protected bool EnsurePhsyicalViewExists ( string template )
92
92
{
93
+ if ( string . IsNullOrWhiteSpace ( template ) )
94
+ {
95
+ string docTypeAlias = UmbracoRouteValues . PublishedRequest . PublishedContent . ContentType . Alias ;
96
+ _logger . LogWarning ( "No physical template file was found for document type with alias {Alias}" , docTypeAlias ) ;
97
+ return false ;
98
+ }
99
+
93
100
ViewEngineResult result = _compositeViewEngine . FindView ( ControllerContext , template , false ) ;
94
101
if ( result . View != null )
95
102
{
@@ -99,6 +106,5 @@ protected bool EnsurePhsyicalViewExists(string template)
99
106
_logger . LogWarning ( "No physical template file was found for template {Template}" , template ) ;
100
107
return false ;
101
108
}
102
-
103
109
}
104
110
}
You can’t perform that action at this time.
0 commit comments