簡體   English   中英

創建asp.net MVC 2預覽版和亞音速3.0.0.3時出錯

[英]error on model creation asp.net MVC 2 preview and subsonic 3.0.0.3

我已經建立了所有東西,以便從2個模型創建一個模型,這樣我就可以為單個模型創建一個視圖。 一個表保存1個報價的信息,第二個表保存該報價內的項目列表。

我得到的錯誤是:

傳遞到詞典中的模型項的類型為'graniteConcepts.Controllers.QuoteViewModel',但是此詞典需要模型類型為'System.Collections.Generic.IEnumerable`1 [graniteConcepts.Controllers.QuoteViewModel]'的模型項。

這是我打電話的結果

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,List,也嘗試了什么都沒有

如果我什么都沒有,即只是new_quote_item quoteItems,那么我得到一個錯誤:

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

說不能將IList轉換為new_online_quote,這就是為什么我首先以IList嘗試它的原因,認為一個列表會掉入另一個列表。

我確定這是我想念的很小的東西,但我只是不知道它是什么。

謝謝

您需要做的是刪除System.Collections.Generic.IEnumerable'。 作為網頁的模型...

您可以在top指令中執行此操作,而應鍵入以下內容:

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

編輯:澄清一下,這是您希望在其中顯示模型的View .ASPX文件中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM