views:

144

answers:

1

hi folks

i have build everything in order to create a model from 2 models so that i can create a view for the single model. one table holds info for 1 quote and the second table holds a list of items within that quote.

the error i get is:

The model item passed into the dictionary is of type 'graniteConcepts.Controllers.QuoteViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[graniteConcepts.Controllers.QuoteViewModel]'.

here is my calling actionresult

public ActionResult finaliseQuote(string quoteid)
    {
        ViewData["quoteid"] = quoteid;

        var model = new QuoteViewModel
        {
            quoteInfo = new_online_quote.SingleOrDefault(x => x.quoteid == Convert.ToInt32(quoteid)),
            quoteItems = new_quote_item.Find(x => x.quote_id == Convert.ToInt32(quoteid))
        };


        return View(model);

    }

and here is my custom model to hold the partnership:

public class QuoteViewModel
{
    public new_online_quote quoteInfo { get; set; }
    public IEnumerable<new_quote_item> quoteItems { get; set; }
}

i have tried IList, List and also tried having nothing

if i have nothing, ie it just new_quote_item quoteItems then i get an error:

on

quoteItems = new_quote_item.Find(x => x.quote_id == Convert.ToInt32(quoteid))

saying that IList cannot be converted to new_online_quote this is why i first tried it as an IList thinking one list would just drop into another.

im sure it is something small that i am missing but i just dont know what it is.

thanks

+3  A: 

What you need to do is remove System.Collections.Generic.IEnumerable'. as a Model for the viewpage...

You can do this at the top directive, instead you should type something like this:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<graniteConcepts.Controllers.QuoteViewModel>" %>

EDIT: To clarify, this is in the View .ASPX file that you wish to present the Model in.

Robban
wicked pal wicked, cant beleive it was only that thanks very much lesson learnt :-)
minus4