Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

I am trying to add reference of my model in the _layout or component view but for latter it's saying two models are not allowed since there is already -

@model IComponent

And when I try to add a model(@model Test.Navigation) on top of my _layout view the error is -

"The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[MyWebSite.ViewModels.Navigation]', but this dictionary requires a model item of type 'DD4T.ContentModel.IPage'."

Please confirm if models other than the IComponent or IPage are allowed? If so, how I can achieve it?

share|improve this question

2 Answers 2

You can use any class as a model in DD4T. Generally in MVC Layout files don't usually have a model. If I was you I would create an Action method called Render in a controller called NavigationController and then call that using Html.Action() in your Layout file.

Your View for this Action can then be the model you want and your logic for rendering the navigation information can be encapsulated in a single method.

share|improve this answer
    
How can I pass model in Action, it only allows the following as paramenter- this HtmlHelper htmlHelper, string actionName, string controllerName, Object routeValues –  user945 Apr 3 at 15:18
    
You should retreive the information for your model and create an instance of your model in the action method rather than trying to pass the model from the view to the action. Think about Model View Controller principles. –  Rob Stevenson-Leggett Apr 3 at 15:28

As far as I know DD4T supports IComponent/IPage as models for the view.

But you can use ViewData or ViewBag (works only for MVC 4 since it's dependent on C# 4.0) classes to pass additional information to the View.

ViewData is a dictionary of key/value pairs and ViewBag uses C# 4.0 features to have dynamic properties that can be accessed in the view.

Read more here.

Hope this helps resolve your query.

share|improve this answer
    
Using VD or Vbag means passing values from Controller to view which will omit the M of MVC, is it not possible to also include Model in _layout as it doesn't require @model IComponent/IPage ? –  user945 Apr 3 at 12:14
    

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.