tags:

views:

69

answers:

2

I would like to have both these views:

  • ~/Views/Customer/Index.aspx
  • ~/Views/Customer/Index.ascx

I would like to setup my MVC website so that when I call return View(viewModel) from the CustomerController.Index() action method, that it looks up the aspx file, but if I call return PartialView(viewModel) that it looks up the ascx file.

I believe the magic involves subclassing ViewEngine and ControllerFactory (so that the ViewLocator.ViewLocationFormats can be modified), but want to check that I'm not over-engineering this solution.

Does anyone have any experience with this?

+1  A: 

Based on the comments above and the suggestion, I think my answer to a different question may provide some help - http://stackoverflow.com/questions/3363847/render-partial-of-same-name-as-parent-view-crashes-webdev-webserver40-exe/3364288#3364288

The issue is that the PartialViewLocationFormats are set to be the same as the ViewLocationFormats. It does not make sense to that a partial view would be an aspx page.

Ahmad
A: 

override WebFormsViewEngine and reimplement ViewLocationFormats and/or PartialViewLocationFormats

Andrew Bullock