2009-09-09 55 views
1

我已經建立了一切,以便從2個模型創建一個模型,以便我可以爲單個模型創建一個視圖。一個表包含1個報價的信息,第二個表包含該報價中的項目列表。模型創建錯誤asp.net MVC 2預覽和亞音速3.0.0.3

我得到的錯誤是:

傳遞到字典的模型產品類型「graniteConcepts.Controllers.QuoteViewModel」的,但這種字典需要類型的「典範項目System.Collections.Generic.IEnumerable` 1 [graniteConcepts.Controllers.QuoteViewModel]」。

這裏是我的電話的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); 

    } 

,這裏是我的自定義模型,以保持合作伙伴關係:

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

我已經試過的IList,列表和也試過一無所有

如果我什麼也沒有,即它只是new_quote_item quoteItems然後我得到一個錯誤:

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

說的IList不能轉換到new_online_quote 這就是爲什麼我第一次嘗試它作爲一個IList思考一個名單將只下降到另一個。

確定它是一個小的,我失蹤,但我只是不知道它是什麼。

感謝

回答

3

你需要做的是去除System.Collections.Generic.IEnumerable」。 作爲的ViewPage模型...

您可以在上面的指令做,而應該鍵入類似這樣:

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

編輯:爲了澄清,這是在查看.ASPX文件,你想介紹模型英寸

+0

邪惡的夥計邪惡的,不能相信它只是非常感謝的教訓:-) – davethecoder 2009-09-09 12:54:56