Reputation: 5518
I have a ServiceStack
.Service
implementation that defines a method that must return HTML
markup, but a fragment only. I tried to just set the View
property of the an HttpResult
object without specifying a layout in the Razor
view nor do I set the Template
property of the result - and I expected to get the view markup only, which is not the case.
The view is derived from ViewPage
. The service function looks like that...
public class SampleService : Service
{
public IHttpResult Get(GetSampleRequest request)
{
return new HttpResult
{
View = "SampleView"
};
}
}
The problem is that ServiceStack
tries to find a default layout (which exists) and uses that. How can I prevent that? In ASP.NET MVC I would usually just return the result from the Partial
extension method; does something similiar exist in ServiceStack
?
Upvotes: 3
Views: 1685
Reputation: 34227
You could also set a layout that contains nothing or just a comment to indicate it was deliberate "_LayoutEmpty.cshtml"
. Kind of a design choice vs an empty string name.
Upvotes: 2
Reputation: 3180
You will need to define a Layout
in your Razor View as empty.
However, setting it to null
just defaults to using the _Layout.cshtml
page (or whatever's defined as your default).
In your Razor View, set the Layout
to ""
, like so:
@{
Layout = "";
}
You could also set Layout = string.Empty
. Both have the same desired effect.
Hope this helps! :)
Upvotes: 5