Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Aug 22, 2008 02:42 AM|LINK
You should create a controller called CarsController, then add a public method Featured which returns a ViewResult passing in a list of featured cars.
public class CarsController : Controller
private ICarService CarService;
public CarsController(ICarService carService)
CarService = carService;
public ActionResult Featured()
var featuredCars = CarService.GetFeaturedCars;
Then you can create your view user control, call it Featured.ascx and put it in ~/Views/Cars/. It should be of type ViewUserControl<IEnumerable<Car>>.
Then in your main index view do the following <%= Html.RenderAction( "Featured", "Cars" ) %>
This will create your CarsController, call the Featured method, and render your Featured.ascx in place.
(You can ignore the bit about the CarService if you like, that's just to show a good testable design practice)