ServiceStack剃须刀 - Html.RenderAction相当于 [英] ServiceStack Razor - Html.RenderAction equivalent

查看:168
本文介绍了ServiceStack剃须刀 - Html.RenderAction相当于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用Html.RenderAction,就像您在ASP.NET MVC的要求。

I have the requirement to use Html.RenderAction like you would in ASP.NET MVC.

比如我有一个主页的新闻和产品上。

For instance I have a Home Page with News and Products on.

我想比如说做

@Html.RenderAction("/api/products/featured")

这将启动新的服务调用并输出模板,HTML流。

Which would start a new service call and output the template to the html stream.

这可能使用ServiceStack剃刀,如果让我怎么做到呢?

Is this possible using ServiceStack Razor and if so how do I accomplish it?

推荐答案

的<一个href=\"https://github.com/ServiceStack/ServiceStack/blob/master/tests/RazorRockstars.Console.Files/Pages/PartialExamples.cshtml\"相对=nofollow> PartialExamples.cshtml 测试页面显示呈现页面,例如里面的Razor视图不同的例子:

The PartialExamples.cshtml test page shows different examples of rendering a razor view inside a page, e.g:

使用新的 RenderToAction()方法,它可以让你执行一个服务,它的渲染局部视图与路由和查询字符串,例如:

Using the new RenderToAction() method which lets you execute a Service and it's rendered partial view with a route and QueryString, e.g:

@Html.RenderAction("/products/1")

这也有一个可选的视图名称,如果你想比默认了不同的看法:

This also takes an optional view name if you want a different view than the default:

@Html.RenderAction("/products/1", "CustomProductView")

有也正常 Html.Partial()来指定需要的视图和模型在页面呈现,例如:

There's also the normal Html.Partial() to specify which view and model you want to render in the page, e.g:

@Html.Partial("GetProduct", 
    base.ExecuteService<ProductService>(s => s.Any(new GetProduct { Id = 1 })))

ExecuteService 简直就是围绕一个包装相当于 ResolveService 在using语句,即:

ExecuteService is simply a wrapper around the equivalent ResolveService in a using statement, i.e:

@{
   Response response = null;
   using (var service = base.ResolveService<ProductService>())
   {
       response = service.Any(new GetProduct { Id = 1 });
   }
}
@Html.Partial("GetProduct", response)

新的 RenderToAction() v4.0.34 + 这是现在的可用MyGet

这篇关于ServiceStack剃须刀 - Html.RenderAction相当于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆