7

I use dd4t and mvc. And I want to make queries from the controllers, make the components to view models and pass the model to the views. So when I try to pass the view model a get exception :

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

And I use the default mvc routing and I don't use the UnityDependencyResolver. I work from very soon with dd4t and I realy have no idea what else to do so I can solve this problem. Here is also the code from my controller

public class HomeController : Controller
{
    public ActionResult Index()
    {
        Criteria criteria = new ItemSchemaCriteria(176);

        SortParameter param1 = new
        SortParameter(SortParameter.ItemCreationDate,
        SortParameter.Descending);
        Query query = new Query(criteria);
        query.AddSorting(param1);
        string[] results = query.ExecuteQuery();

        ComponentFactory cf = new ComponentFactory();
        cf.ComponentProvider = new TridionComponentProvider();
        var components = cf.GetComponents(results);

        List<ArticleViewModel> articles = components.AsQueryable()
                                                       .Select(ArticleViewModel
                                                       .FromArticleComponent)
                                                       .Take(7).ToList();

        return View(articles);
    }
}

Thanks and if you need more specifics, just tell me.

  • Could you also post the code from your corresponding cshtml file – Harald Hoffelinck Nov 20 '13 at 9:03
6

You are calling the view with a model of the type List. This is fine, just start your razor view with the line:

@model List<ArticleViewModel>
| improve this answer | |
3

I guess you have the basic DD4T pipeline working - i.e. published content (using DD4T TBBS), a view corresponding to your page template and a view corresponding to your component template, page and component controllers?

Ultimately the view that the ViewEngine has found for this action - presumably /Views/Home/Index.cshtml is expecting an @model of DD4T.ContentModel.IPage but your passing an IList.

How is this controller being called?

Any reason your not following the Visual Studio template to get going first?

Cheers

| improve this answer | |

Your Answer

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

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