I have following requirements for DD4T.
- I want to write custom business logic for my components.
- I don't want to write business logic in my component views, as it will violate the mvc principles
- I want to write Unit Tests for my component.
This is what I thought for
Create a Custom Controller and Create an Action to represent particular component and build the model. Then return the model to the view.
public class ArticleViewController:TridionControllerBase { // GET: ArticleView public ActionResult ArticleViewCT(IComponentPresentation componentPresentation) { var model = ComponentViewModelBuilder.Build<ArticleViewModel>(componentPresentation.Component); //or Some Extra database calls return View(model); } }
then in Page template I want to call this Action
@{Html.RenderAction("ArticleViewCT", "ArticleView");};
but it's throwing an error
[MissingMethodException: Cannot create an instance of an interface. Object type 'DD4T.ContentModel.IComponentPresentation'.]
Can you suggest me to implement, which helps to solve my problems. I love to work as normal MVC works. I am also using this package to create viewModels ViewModel for DD4t