我只是直接跳到它。我有一個叫做「請求」的模型,我使用LINQ to SQL創建。我有另一個模型叫「評論」。 「請求」可以有許多「評論」。嘗試在ASP.NET MVC中的EntityCollection中循環實體時出現無效投射
在我的控制器我有這樣的代碼:
public ViewResult Details(int? id)
{
return View(requestService.GetRequest(id));
}
在我看來,我有這個標記(編輯爲簡潔起見)
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Models.Request>" %>
<p>
CustomerNumber:
<%= Html.Encode(Model.CustomerNumber) %>
</p>
<p>
CustomerName:
<%= Html.Encode(Model.CustomerName) %>
</p>
... etc ...
<table id="comments">
<thead>
<tr>
<th>Date</th>
<th>User Name</th>
<th>User IP</th>
<th>Comment</th>
</tr>
</thead>
<tbody>
<% foreach (var comment in Model.Comments) { %>
<tr>
<td><%= Html.Encode(comment.CommentDate) %></td>
<td><%= Html.Encode(comment.CommentUserName) %></td>
<td><%= Html.Encode(comment.CommentIP) %></td>
<td><%= Html.Encode(comment.Comment1) %></td>
</tr>
<% } %>
</tbody>
</table>
好吧,這裏發生了什麼。當我調用Details方法/動作時,它會使用我的服務層去獲取用戶希望看到的請求。但是,當它遍歷與請求相關的註釋時,它會拋出一個「無效的拋出異常」並死亡。這段代碼兩天前工作正確,沒有對這部分項目(其他文件,但不是這個東西)進行修改。
我試圖找到鑄造問題,我很茫然。請幫助我,因爲我認爲這是我的項目真正起飛之前克服的最後障礙。如果您需要更多信息,請告訴我。
什麼是異常的完整堆棧和完整錯誤消息? – 2009-09-25 17:27:38
這是最後幾行......不能發佈完整的堆棧跟蹤。 在System.Data.SqlClient.SqlBuffer.get_Int32() 在System.Data.SqlClient.SqlDataReader.GetInt32(的Int32ⅰ) 在Read_Comment(ObjectMaterializer'1) 在System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader '2.MoveNext() at System.Data.Linq.EntitySet'1.Load() at System.Data.Linq.EntitySet'1.GetEnumerator() at ASP.views_home_details_aspx .__ RenderContent1(HtmlTextWriter __w,Control parameterContainer)在c:\ Code \ Prototypes \ PremiumFreightMVC \ Views \ Home \ Details中。aspx:第139行 – 2009-10-06 18:18:18