How to use ServiceStack Templates to support dynamic results based on request type?Is there a way to inject support for the F# Option type into ServiceStack?ServiceStack custom format and vendor specific content typesServiceStack/Razor - how to get POST data on submit form?How can I get AngularJS working with the ServiceStack FallbackRoute attribute to support HTML5 pushstate Urls?How to get ServiceStack to serialize a dynamic (ExpandoObject) property on requestServiceStack support for conditionally omitting fields from a REST response on a per-call basisDoes ServiceStack support POSTs from plain html?Possible to bypass servicestack's authentication mechanisms for non standard authenticationPassing a Dictionary object as part of a request on ServiceStack SwaggerServiceStack - Autoquery Request logs issue
Will removing shelving screws from studs damage the studs?
Count the number of triangles
What to do about my 1-month-old boy peeing through diapers?
Fantasy Macro Economics: What would Merfolk Trade?
Alternatives to Network Backup
Shift lens vs move body?
How could a self contained organic body propel itself in space
Grep contents before a colon
Group riding etiquette
Why does a sticker slowly peel off, but if it is pulled quickly it tears?
Force SQL Server to use fragmented indexes?
Why did Lucius make a deal out of Buckbeak hurting Draco but not about Draco being turned into a ferret?
Federal Pacific 200a main panel problem with oversized 100a 2pole breaker
If I said I had $100 when asked, but I actually had $200, would I be lying by omission?
Is a memoized pure function itself considered pure?
Book featuring a child learning from a crowdsourced AI book
Find feasible point in polynomial time in linear programming
Dotted background on a flowchart
What is the name of this plot that has rows with two connected dots?
How do we improve collaboration with problematic tester team?
Why does this London Underground poster from 1924 have a Star of David atop a Christmas tree?
Why is getting a PhD considered "financially irresponsible" by some people?
Term used to describe a person who predicts future outcomes
How do solar inverter systems easily add AC power sources together?
How to use ServiceStack Templates to support dynamic results based on request type?
Is there a way to inject support for the F# Option type into ServiceStack?ServiceStack custom format and vendor specific content typesServiceStack/Razor - how to get POST data on submit form?How can I get AngularJS working with the ServiceStack FallbackRoute attribute to support HTML5 pushstate Urls?How to get ServiceStack to serialize a dynamic (ExpandoObject) property on requestServiceStack support for conditionally omitting fields from a REST response on a per-call basisDoes ServiceStack support POSTs from plain html?Possible to bypass servicestack's authentication mechanisms for non standard authenticationPassing a Dictionary object as part of a request on ServiceStack SwaggerServiceStack - Autoquery Request logs issue
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
With ServiceStack's Razor Story we have a variety of ways of selecting which Razor View we want to use to render a page. Even better, and critical in my case, is we can pass in a Content-Type header (or query string parameter, or even page "suffix") as well to return the raw model in a variety of formats.
Is there any way to use ServiceStack Templates (now known as SharpScript) to do the same thing? I follow the example here but I just get back the standard HTML format response. It doesn't use my template, no matter how named.
Following the example in the v5.5 Release Notes:
[Route("/hello/Name")]
public class Hello : IReturn<HelloResponse>
public string Name get; set;
public class HelloResponse
public string Result get; set;
public class HelloService : Service
public object Any(Hello request) => new HelloResponse Result = $"Hello, request.Name!" ;
Going to /hello/World?format=html
provides me the standard HTML report, not my template. I followed another example to force it to use the template ....
public object Any(Hello request) =>
new PageResult(Request.GetPage("examples/hello"))
Model = request.Name
;
... and it ALWAYS returns my template, even if I specify /hello/World?format=json
.
Is there any way to have Razor-like view selection for ServiceStack + ScriptSharp pages, but also support different response formats?
servicestack servicestack-razor
add a comment |
With ServiceStack's Razor Story we have a variety of ways of selecting which Razor View we want to use to render a page. Even better, and critical in my case, is we can pass in a Content-Type header (or query string parameter, or even page "suffix") as well to return the raw model in a variety of formats.
Is there any way to use ServiceStack Templates (now known as SharpScript) to do the same thing? I follow the example here but I just get back the standard HTML format response. It doesn't use my template, no matter how named.
Following the example in the v5.5 Release Notes:
[Route("/hello/Name")]
public class Hello : IReturn<HelloResponse>
public string Name get; set;
public class HelloResponse
public string Result get; set;
public class HelloService : Service
public object Any(Hello request) => new HelloResponse Result = $"Hello, request.Name!" ;
Going to /hello/World?format=html
provides me the standard HTML report, not my template. I followed another example to force it to use the template ....
public object Any(Hello request) =>
new PageResult(Request.GetPage("examples/hello"))
Model = request.Name
;
... and it ALWAYS returns my template, even if I specify /hello/World?format=json
.
Is there any way to have Razor-like view selection for ServiceStack + ScriptSharp pages, but also support different response formats?
servicestack servicestack-razor
add a comment |
With ServiceStack's Razor Story we have a variety of ways of selecting which Razor View we want to use to render a page. Even better, and critical in my case, is we can pass in a Content-Type header (or query string parameter, or even page "suffix") as well to return the raw model in a variety of formats.
Is there any way to use ServiceStack Templates (now known as SharpScript) to do the same thing? I follow the example here but I just get back the standard HTML format response. It doesn't use my template, no matter how named.
Following the example in the v5.5 Release Notes:
[Route("/hello/Name")]
public class Hello : IReturn<HelloResponse>
public string Name get; set;
public class HelloResponse
public string Result get; set;
public class HelloService : Service
public object Any(Hello request) => new HelloResponse Result = $"Hello, request.Name!" ;
Going to /hello/World?format=html
provides me the standard HTML report, not my template. I followed another example to force it to use the template ....
public object Any(Hello request) =>
new PageResult(Request.GetPage("examples/hello"))
Model = request.Name
;
... and it ALWAYS returns my template, even if I specify /hello/World?format=json
.
Is there any way to have Razor-like view selection for ServiceStack + ScriptSharp pages, but also support different response formats?
servicestack servicestack-razor
With ServiceStack's Razor Story we have a variety of ways of selecting which Razor View we want to use to render a page. Even better, and critical in my case, is we can pass in a Content-Type header (or query string parameter, or even page "suffix") as well to return the raw model in a variety of formats.
Is there any way to use ServiceStack Templates (now known as SharpScript) to do the same thing? I follow the example here but I just get back the standard HTML format response. It doesn't use my template, no matter how named.
Following the example in the v5.5 Release Notes:
[Route("/hello/Name")]
public class Hello : IReturn<HelloResponse>
public string Name get; set;
public class HelloResponse
public string Result get; set;
public class HelloService : Service
public object Any(Hello request) => new HelloResponse Result = $"Hello, request.Name!" ;
Going to /hello/World?format=html
provides me the standard HTML report, not my template. I followed another example to force it to use the template ....
public object Any(Hello request) =>
new PageResult(Request.GetPage("examples/hello"))
Model = request.Name
;
... and it ALWAYS returns my template, even if I specify /hello/World?format=json
.
Is there any way to have Razor-like view selection for ServiceStack + ScriptSharp pages, but also support different response formats?
servicestack servicestack-razor
servicestack servicestack-razor
edited Mar 28 at 13:31
jklemmack
asked Mar 27 at 20:37
jklemmackjklemmack
2,6261 gold badge24 silver badges41 bronze badges
2,6261 gold badge24 silver badges41 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
It's hard to answer a vague question like this without details of a specific scenario you want to achieve that's not working.
You can return Sharp Pages in a number of ways:
- When it's requested directly as a content page, e.g
/dir/page
->/dir/page.html
- Using Page Based Routing, e.g
/dir/1
->/dir/_id.html
- As a View Page in response to a Service when it's named after the Request DTO or Response DTO, e.g
/contacts/1
->/Views/GetContact.html
or/Views/GetContactResponse.html
Select which view to render inside your Service by returning your Response DTO inside a custom HttpResult
:
public object Any(MyRequest request)
...
return new HttpResult(response)
View = "CustomPage", // -> /Views/CustomPage.html
//Template = "_custom-layout",
;
Add the [ClientCanSwapTemplates]
Request Filter attribute to let the View and Template by modified on the QueryString, e.g: ?View=CustomPage&Template=_custom-layout
[ClientCanSwapTemplates]
public object Any(MyRequest request) => ...
Choosing which page you want to render inside your Model View Controller Service by returning a custom PageResult
:
public class CustomerServices : Service
public object Any(ViewCustomer request) =>
new PageResult(Request.GetPage("examples/customer"))
Model = TemplateQueryData.GetCustomer(request.Id)
;
Note: That the
SharpPagesFeature
resolves pages using your cascadingAppHost.VirtualFileSources
. In .NET Core it's configured to use its WebRoot, e.g/wwwroot
.
For Sharp Pages to return its Response in Multiple Content Types:
as well to return the raw model in a variety of formats.
You need to use a Sharp APIs which return
a value, e.g. /hello/_name/index.html:
return
1
I think there was a gap in the docs, or at minimum my understanding. I dug into the code and realized it was implemented almost exactly like Razor ViewPage selection. I just returned anHttpResult
with aView
property set to my template page name ("account" in this case) and voila! I think another case of analysis paralysis & not seeing this spelled out in the docs.
– jklemmack
Mar 27 at 21:36
add a comment |
To succinctly answer my own question, the first option from @mythz is what I needed. After calling Plugins.Add(new SharpPagesFeature())
in my AppHost
, I needed to return HttpResult
from my service method:
public object Any(MyRequest request)
...
return new HttpResult(response)
View = "CustomPage", // -> /Views/CustomPage.html
//Template = "_custom-layout",
;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55386039%2fhow-to-use-servicestack-templates-to-support-dynamic-results-based-on-request-ty%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's hard to answer a vague question like this without details of a specific scenario you want to achieve that's not working.
You can return Sharp Pages in a number of ways:
- When it's requested directly as a content page, e.g
/dir/page
->/dir/page.html
- Using Page Based Routing, e.g
/dir/1
->/dir/_id.html
- As a View Page in response to a Service when it's named after the Request DTO or Response DTO, e.g
/contacts/1
->/Views/GetContact.html
or/Views/GetContactResponse.html
Select which view to render inside your Service by returning your Response DTO inside a custom HttpResult
:
public object Any(MyRequest request)
...
return new HttpResult(response)
View = "CustomPage", // -> /Views/CustomPage.html
//Template = "_custom-layout",
;
Add the [ClientCanSwapTemplates]
Request Filter attribute to let the View and Template by modified on the QueryString, e.g: ?View=CustomPage&Template=_custom-layout
[ClientCanSwapTemplates]
public object Any(MyRequest request) => ...
Choosing which page you want to render inside your Model View Controller Service by returning a custom PageResult
:
public class CustomerServices : Service
public object Any(ViewCustomer request) =>
new PageResult(Request.GetPage("examples/customer"))
Model = TemplateQueryData.GetCustomer(request.Id)
;
Note: That the
SharpPagesFeature
resolves pages using your cascadingAppHost.VirtualFileSources
. In .NET Core it's configured to use its WebRoot, e.g/wwwroot
.
For Sharp Pages to return its Response in Multiple Content Types:
as well to return the raw model in a variety of formats.
You need to use a Sharp APIs which return
a value, e.g. /hello/_name/index.html:
return
1
I think there was a gap in the docs, or at minimum my understanding. I dug into the code and realized it was implemented almost exactly like Razor ViewPage selection. I just returned anHttpResult
with aView
property set to my template page name ("account" in this case) and voila! I think another case of analysis paralysis & not seeing this spelled out in the docs.
– jklemmack
Mar 27 at 21:36
add a comment |
It's hard to answer a vague question like this without details of a specific scenario you want to achieve that's not working.
You can return Sharp Pages in a number of ways:
- When it's requested directly as a content page, e.g
/dir/page
->/dir/page.html
- Using Page Based Routing, e.g
/dir/1
->/dir/_id.html
- As a View Page in response to a Service when it's named after the Request DTO or Response DTO, e.g
/contacts/1
->/Views/GetContact.html
or/Views/GetContactResponse.html
Select which view to render inside your Service by returning your Response DTO inside a custom HttpResult
:
public object Any(MyRequest request)
...
return new HttpResult(response)
View = "CustomPage", // -> /Views/CustomPage.html
//Template = "_custom-layout",
;
Add the [ClientCanSwapTemplates]
Request Filter attribute to let the View and Template by modified on the QueryString, e.g: ?View=CustomPage&Template=_custom-layout
[ClientCanSwapTemplates]
public object Any(MyRequest request) => ...
Choosing which page you want to render inside your Model View Controller Service by returning a custom PageResult
:
public class CustomerServices : Service
public object Any(ViewCustomer request) =>
new PageResult(Request.GetPage("examples/customer"))
Model = TemplateQueryData.GetCustomer(request.Id)
;
Note: That the
SharpPagesFeature
resolves pages using your cascadingAppHost.VirtualFileSources
. In .NET Core it's configured to use its WebRoot, e.g/wwwroot
.
For Sharp Pages to return its Response in Multiple Content Types:
as well to return the raw model in a variety of formats.
You need to use a Sharp APIs which return
a value, e.g. /hello/_name/index.html:
return
1
I think there was a gap in the docs, or at minimum my understanding. I dug into the code and realized it was implemented almost exactly like Razor ViewPage selection. I just returned anHttpResult
with aView
property set to my template page name ("account" in this case) and voila! I think another case of analysis paralysis & not seeing this spelled out in the docs.
– jklemmack
Mar 27 at 21:36
add a comment |
It's hard to answer a vague question like this without details of a specific scenario you want to achieve that's not working.
You can return Sharp Pages in a number of ways:
- When it's requested directly as a content page, e.g
/dir/page
->/dir/page.html
- Using Page Based Routing, e.g
/dir/1
->/dir/_id.html
- As a View Page in response to a Service when it's named after the Request DTO or Response DTO, e.g
/contacts/1
->/Views/GetContact.html
or/Views/GetContactResponse.html
Select which view to render inside your Service by returning your Response DTO inside a custom HttpResult
:
public object Any(MyRequest request)
...
return new HttpResult(response)
View = "CustomPage", // -> /Views/CustomPage.html
//Template = "_custom-layout",
;
Add the [ClientCanSwapTemplates]
Request Filter attribute to let the View and Template by modified on the QueryString, e.g: ?View=CustomPage&Template=_custom-layout
[ClientCanSwapTemplates]
public object Any(MyRequest request) => ...
Choosing which page you want to render inside your Model View Controller Service by returning a custom PageResult
:
public class CustomerServices : Service
public object Any(ViewCustomer request) =>
new PageResult(Request.GetPage("examples/customer"))
Model = TemplateQueryData.GetCustomer(request.Id)
;
Note: That the
SharpPagesFeature
resolves pages using your cascadingAppHost.VirtualFileSources
. In .NET Core it's configured to use its WebRoot, e.g/wwwroot
.
For Sharp Pages to return its Response in Multiple Content Types:
as well to return the raw model in a variety of formats.
You need to use a Sharp APIs which return
a value, e.g. /hello/_name/index.html:
return
It's hard to answer a vague question like this without details of a specific scenario you want to achieve that's not working.
You can return Sharp Pages in a number of ways:
- When it's requested directly as a content page, e.g
/dir/page
->/dir/page.html
- Using Page Based Routing, e.g
/dir/1
->/dir/_id.html
- As a View Page in response to a Service when it's named after the Request DTO or Response DTO, e.g
/contacts/1
->/Views/GetContact.html
or/Views/GetContactResponse.html
Select which view to render inside your Service by returning your Response DTO inside a custom HttpResult
:
public object Any(MyRequest request)
...
return new HttpResult(response)
View = "CustomPage", // -> /Views/CustomPage.html
//Template = "_custom-layout",
;
Add the [ClientCanSwapTemplates]
Request Filter attribute to let the View and Template by modified on the QueryString, e.g: ?View=CustomPage&Template=_custom-layout
[ClientCanSwapTemplates]
public object Any(MyRequest request) => ...
Choosing which page you want to render inside your Model View Controller Service by returning a custom PageResult
:
public class CustomerServices : Service
public object Any(ViewCustomer request) =>
new PageResult(Request.GetPage("examples/customer"))
Model = TemplateQueryData.GetCustomer(request.Id)
;
Note: That the
SharpPagesFeature
resolves pages using your cascadingAppHost.VirtualFileSources
. In .NET Core it's configured to use its WebRoot, e.g/wwwroot
.
For Sharp Pages to return its Response in Multiple Content Types:
as well to return the raw model in a variety of formats.
You need to use a Sharp APIs which return
a value, e.g. /hello/_name/index.html:
return
answered Mar 27 at 21:24
mythzmythz
122k14 gold badges200 silver badges345 bronze badges
122k14 gold badges200 silver badges345 bronze badges
1
I think there was a gap in the docs, or at minimum my understanding. I dug into the code and realized it was implemented almost exactly like Razor ViewPage selection. I just returned anHttpResult
with aView
property set to my template page name ("account" in this case) and voila! I think another case of analysis paralysis & not seeing this spelled out in the docs.
– jklemmack
Mar 27 at 21:36
add a comment |
1
I think there was a gap in the docs, or at minimum my understanding. I dug into the code and realized it was implemented almost exactly like Razor ViewPage selection. I just returned anHttpResult
with aView
property set to my template page name ("account" in this case) and voila! I think another case of analysis paralysis & not seeing this spelled out in the docs.
– jklemmack
Mar 27 at 21:36
1
1
I think there was a gap in the docs, or at minimum my understanding. I dug into the code and realized it was implemented almost exactly like Razor ViewPage selection. I just returned an
HttpResult
with a View
property set to my template page name ("account" in this case) and voila! I think another case of analysis paralysis & not seeing this spelled out in the docs.– jklemmack
Mar 27 at 21:36
I think there was a gap in the docs, or at minimum my understanding. I dug into the code and realized it was implemented almost exactly like Razor ViewPage selection. I just returned an
HttpResult
with a View
property set to my template page name ("account" in this case) and voila! I think another case of analysis paralysis & not seeing this spelled out in the docs.– jklemmack
Mar 27 at 21:36
add a comment |
To succinctly answer my own question, the first option from @mythz is what I needed. After calling Plugins.Add(new SharpPagesFeature())
in my AppHost
, I needed to return HttpResult
from my service method:
public object Any(MyRequest request)
...
return new HttpResult(response)
View = "CustomPage", // -> /Views/CustomPage.html
//Template = "_custom-layout",
;
add a comment |
To succinctly answer my own question, the first option from @mythz is what I needed. After calling Plugins.Add(new SharpPagesFeature())
in my AppHost
, I needed to return HttpResult
from my service method:
public object Any(MyRequest request)
...
return new HttpResult(response)
View = "CustomPage", // -> /Views/CustomPage.html
//Template = "_custom-layout",
;
add a comment |
To succinctly answer my own question, the first option from @mythz is what I needed. After calling Plugins.Add(new SharpPagesFeature())
in my AppHost
, I needed to return HttpResult
from my service method:
public object Any(MyRequest request)
...
return new HttpResult(response)
View = "CustomPage", // -> /Views/CustomPage.html
//Template = "_custom-layout",
;
To succinctly answer my own question, the first option from @mythz is what I needed. After calling Plugins.Add(new SharpPagesFeature())
in my AppHost
, I needed to return HttpResult
from my service method:
public object Any(MyRequest request)
...
return new HttpResult(response)
View = "CustomPage", // -> /Views/CustomPage.html
//Template = "_custom-layout",
;
answered Mar 28 at 13:33
jklemmackjklemmack
2,6261 gold badge24 silver badges41 bronze badges
2,6261 gold badge24 silver badges41 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55386039%2fhow-to-use-servicestack-templates-to-support-dynamic-results-based-on-request-ty%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown