0

I've thrown some of these into my new MVC project for pages where I need 'widgets' on the screen that are on multiple pages. But I'm thinking of scrapping them and using RenderAction instead.

All my components use ajax to populate themselves, either upon loading or if they're like a mini search box using things like autocomplete or even an ajax query to show some search results.

As a result I have to create an extra controller, so I have ViewComponents->MySearchComponent.cs which has the Invoke method returning a View, but then I have to create another controller called MySearchComponentController to put the relevant ajax methods on for doing the searches. This also means duplicating a lot of dependency injection code and setup. Also I have to create a new folder with a single file, a poorly named 'Default.cshtml' for every single component which makes navigating around files in VS a pain when you have 5 Default.cshtmls open (I appreciate you can rename it but why should you have to?).

I am tempted to just put everything into a controller and have a Shared->Components folder for all the views. It will make the codebase MUCH nicer and I can't really see a disadvantage using RenderAction.

Specific questions:

  • Am I missing something, such as a piece of functionality I don't know about, that solves my problems (naming convention, having to create an extra controller for any ajax methods, having to create an extra folder for every component)

  • Is the reason for my confusion that they have another use case, and I am using the incorrect technology to solve my problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.