Question

Is there a way to return the ASP.NET MVC equivalent of a PartialViewResult (stand-alone partial) in ServiceStack.Razor?

In my service, I would like to return the response DTO as a rendered Partial as opposed to a complete View; again, I just need some rendered HTML snippets for this service.

The use case is to make an AJAX call to a service and then have the service returned the rendered partial.

In one of my views, I just tried the following, but it is still returning the full HTML markup and not just the small snippet.

inside travel.cshtml...

@model TravelScenarioResponse

@Model.Name
Was it helpful?

Solution

You can specify to not use any Layout with @layout "", e.g:

@layout ""
@model TravelScenarioResponse

@Model.Name

Otherwise if you want the same view to be used with multiple layouts and as a partial you can add an Views/Empty.cshtml that just contains:

@RenderBody()

And use that layout in any of the View/Template overrides documented in EmailContacts. E.g. you can decorate your Service or action with a [ClientCanSwapTemplates] attribute, e.g:

[ClientCanSwapTemplates]
public class MyService : Service { ... }

And then the client can specify what view they want to render service with, so you can view a partial by specifying ?Template=Empty on the query string, e.g:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top