1

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
4

1 回答 1

1

您可以指定不使用任何 Layout @layout "",例如:

@layout ""
@model TravelScenarioResponse

@Model.Name

否则,如果您希望将同一个视图用于多个布局并且作为部分布局,您可以添加仅包含以下内容的Views/Empty.cshtml

@RenderBody()

并在 EmailContacts 中记录的任何视图/模板覆盖中使用该布局。[ClientCanSwapTemplates]例如,您可以使用属性装饰您的服务或操作,例如:

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

然后客户端可以指定他们想要使用哪个视图来呈现服务,因此您可以通过?Template=Empty在查询字符串上指定来查看部分视图,例如:

于 2014-03-14T04:00:33.393 回答