I am using MVC preview 2 framework to develop web sites and I am following MVCStorefront tutorials to get a good feel on MVC.
Can you tell me why I can't use RenderView() method ?
Am I missing something or can I use View() instead ? What's the difference between these methods..
Thanks
Here is where Rob is using RenderView in his tutorial.
[TestMethod]
public void CatalogController_IndexMethod_ShouldReturn_Categories_And_Data_For_Parent1() {
CatalogController c = new CatalogController(_repository);
RenderViewResult result = (RenderViewResult)c.Index("Parent1", "Sub10");
CatalogController.CatalogData data = (CatalogController.CatalogData)result.ViewData;
Assert.IsNotNull(data.Category);
Assert.IsNotNull(data.SubCategory);
Assert.IsNotNull(data.SubCategory.Products);
Assert.IsTrue(data.SubCategory.Products.Count() > 0);
Assert.IsNotNull(result);
}
I can't use RenderView. It says " the name 'RenderView' does not exist in the current context
Here's the link : http://www.asp.net/learn/mvc-videos/video-357.aspx
Here is an index method from the CatalogController class :
public ActionResult Index(string category, string subcategory) {
//instantiate the service
CatalogService svc = new CatalogService(_repository);
//the ViewData class
CatalogData data = new CatalogData();
//pull all the categories for the navigation
data.Categories = svc.GetCategories();
//pull the category based on subcategory name
data.Category = data.Categories.WithCategoryName(category);
//catch for bad data
if (data.Category == null) {
data.Category = data.Categories.DefaultCategory();
data.SubCategory = data.Category.SubCategories[0];
} else {
data.SubCategory = data.Categories.WithCategoryName(subcategory);
//catch for bad SubCategory
data.SubCategory= data.SubCategory ?? data.Category.SubCategories[0];
}
return RenderView("Index",data);
}
I am also having a problem with the casting of result.ViewData in CatalogData type which is class that contains data. It says : Cannot convert type System.Web.Mvc.ViewDataDictionary to Commerce.MVC.Web.Controllers.CatalogController.CatalogData