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?

5
  • Sorry for not being able to provide an answer, but what's PartialView() there for anyway? I thought the point was to provide the fuctionality you are trying to achieve. Commented Sep 11, 2010 at 16:59
  • 2
    Why not just call them different names? Commented Sep 11, 2010 at 17:06
  • 1
    I second @JcMalta's suggestion. You're probably best renaming Index.ascx to something like IndexPartial.ascx. Why re-invent the wheel if you're going to return a PartialView for it anyway? Commented Sep 11, 2010 at 18:20
  • 2
    I think my answer to a different question may provide some help stackoverflow.com/questions/3363847/…. The issue is that the partial view locations are set to be the same as the viewlocations. Commented Sep 11, 2010 at 19:09
  • 2
    @Ahmad, you could link to your other answer in the answer. Hate to see you not get accepted for this because you have the perfect solution. Commented Sep 11, 2010 at 21:21

2 Answers 2

2

Based on the comments above and the suggestion, I think my answer to a different question may provide some help - Render Partial of same name as parent View - Crashes WebDev.WebServer40.exe

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.

Sign up to request clarification or add additional context in comments.

Comments

0

override WebFormsViewEngine and reimplement ViewLocationFormats and/or PartialViewLocationFormats

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.