The correct way to write an ASP.NET MVC action that returns a PartialViewResult

I wrote an Action method for the ASP.NET MVC controller, which is used to provide the model with user control.

public class ProductsController: Controller {

public PartialViewResult ProductSummary() { ViewData.Model = new ProductSummaryModel("42"); // dummy data for now return new PartialViewResult() { ViewData = ViewData }; } } 

I am using the Microsoft.Web.Mvc dll 'futures' and the visualization of the control in my main view as follows:

 <% Html.RenderAction<ProductsController>(x => x.ProductSummary()); %> 

What I have here seems to work very well, but I tried to do google new PartialResult() to find out if I should have the right templates.

Currently this search contains only 4 results!

So, I thought that I was doing something wrong in my controller. What is the correct way to create an action method that returns a partial view? And what (if anything) is wrong or bad in what I do.

+4
source share
1 answer

I usually use:

 return PartialView("MyView", myModel); 

But this just returns a new PartialViewResult ("MyView", myModel), so it's a potato / potato.

+5
source

All Articles