The PartialExamples.cshtml test page shows various examples of visualizing a razor inside a page, for example:
Using the new RenderToAction() method, which allows you to execute the Service and display a partial view using the route and QueryString, for example:
@Html.RenderAction("/products/1")
This also accepts an optional view name if you want a different view than the default:
@Html.RenderAction("/products/1", "CustomProductView")
There is also normal Html.Partial() to indicate which view and model you want to display on the page, for example:
@Html.Partial("GetProduct", base.ExecuteService<ProductService>(s => s.Any(new GetProduct { Id = 1 })))
ExecuteService is just a wrapper around an 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)
A new RenderToAction() method in Razor Views was added in v4.0.34 + , which is now available in MyGet .
source share