forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDefaultViewAttribute.cs
More file actions
36 lines (33 loc) · 1.28 KB
/
DefaultViewAttribute.cs
File metadata and controls
36 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using ServiceStack.ServiceHost;
namespace ServiceStack.ServiceInterface
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public class DefaultViewAttribute : RequestFilterAttribute
{
public string View { get; set; }
public string Template { get; set; }
public DefaultViewAttribute() { }
public DefaultViewAttribute(string view) : this(view, null) { }
public DefaultViewAttribute(string view, string template)
{
View = view;
Template = template;
}
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
if (!string.IsNullOrEmpty(View))
{
object currentView;
if (!req.Items.TryGetValue("View", out currentView) || string.IsNullOrEmpty(currentView as string))
req.Items["View"] = View;
}
if (!string.IsNullOrEmpty(Template))
{
object currentTemplate;
if (!req.Items.TryGetValue("Template", out currentTemplate) || string.IsNullOrEmpty(currentTemplate as string))
req.Items["Template"] = Template;
}
}
}
}