2011-05-03 83 views
0

我試圖建立一個店面他,因爲我張貼我迷茫讓我們通過ASP.NET MVC顯示奇怪的結果

StoreViewModel 公共類StoreViewModel

{ 
    public IEnumerable<GetStoreFrontItems_Result> StoreFrontItems { get; set; } 
} 

的Index.aspx

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

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> 
    ..:: Gods Creation Taxidermy :: Store ::.. 
</asp:Content> 

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 

    <div class="maintext"> 
     <h2 class="sectionHeader2">:: Gods Creation Taxidermy : Store Items ::</h2> 
     <br /> 
     At times I end up with items and mounts that the owner never came to pick up, so I put them up for sale to help generate 
     some revenue for Gods Creation Taxidermy. 

     <strong>NOTE:</strong> Now before you freak out and think I'm going to sell your mount remember the items for sale are several years old 
     and the owner simply didnt make the final payment or for some reason left it here. 

     <% Html.DataList(Model.StoreFrontItems).Columns(7).Item(item => 
     { 
      item.Template(storeItems => 
      {%> 
       <div style="margin-right:45px; line-height:150%;"> 
        <span><%: Html.ActionLink(storeItems.CategoryName, "List", new { @animal = storeItems.CategoryName });%></span>      
       </div> 
     <%--  <div style="margin-right:45px; line-height:150%;"> 
        <span><% = galleryImage.ItemName%></span> 
       </div> 
       <div style="margin-right:45px; line-height:150%;"> 
        <span><% = galleryImage.ItemPrice%></span> 
       </div>--%> 
        <%}); 
     }).Render(); %> 

    </div> 
</asp:Content> 

<asp:Content ID="Content3" ContentPlaceHolderID="MetaTagsContent" runat="server"> 
</asp:Content> 

<asp:Content ID="Content4" ContentPlaceHolderID="LeftColumnContent" runat="server"> 
</asp:Content> 

GetStoreFrontItems_Result與函數導入生成。繼承人的codefrom指數StoreController:

[CanonicalUrlAttribute("Store")] 
[CompressionFilter(Order = 1)] 
[CacheFilter(CacheDuration = 120, Order = 2)] 
public virtual ActionResult Index() 
{ 
    GodsCreationTaxidermyEntities context = new GodsCreationTaxidermyEntities(); 
    var viewModel = new StoreIndexViewModel() { StoreFrontItems = context.GetStoreFrontItems() }; 
    return View(viewModel); 

這裏有一些scheenshots,一個顯示錯誤和其他顯示哪些內容顯示出來(如果你需要更多的代碼,然後讓我)在這裏輸入的形象描述

Weird Errorenter image description here

+0

你似乎已經忘記了屏幕截圖,從而導致錯誤,因此也就是這個問題。 – 2011-05-03 23:39:23

+0

我沒有看到錯誤的截圖。你能證實嗎? – ataddeini 2011-05-03 23:40:28

+0

我忘了補充,他們現在在那裏 – PsychoCoder 2011-05-03 23:46:37

回答

2

就錯誤而言,你已經顯示了代碼,不可能回答它爲什麼會發生(雖然錯誤消息似乎不僅僅是自我解釋)。就垃圾角色而言,它們是由您在操作中使用的Compression過濾器引起的。這裏有一個blog post,它解釋了完美的原因以及如何修復它。

所提出的解決方案是把你的Global.asax以下取消ASP.NET的效果剝你的CompressionFilter可能在異常的情況下,增加了自定義壓縮HTTP標頭:

protected void Application_PreSendRequestHeaders() 
{ 
    // ensure that if GZip/Deflate Encoding is applied that headers are set 
    // also works when error occurs if filters are still active 
    HttpResponse response = HttpContext.Current.Response; 
    if (response.Filter is GZipStream && response.Headers["Content-encoding"] != "gzip") 
     response.AppendHeader("Content-encoding", "gzip"); 
    else if (response.Filter is DeflateStream && response.Headers["Content-encoding"] != "deflate") 
     response.AppendHeader("Content-encoding", "deflate"); 
} 
+0

我會顯示更多的代碼,但這個項目是相當大的,並不確定要發佈什麼和不發佈。感謝博客鏈接,我會讓你知道它是如何發生的。 – PsychoCoder 2011-05-04 16:24:11

+0

這正是我所需要的。非常讚賞 – PsychoCoder 2011-05-04 17:40:26

+0

哇,我不能相信這個問題/答案在過去5年沒有收到更多的觀點和贊成票。這對我來說是非常有用的,因爲我知道我有一個錯誤,無論何時我得到垃圾結果,但不知道如何讓它直到現在才顯示錯誤而不是垃圾。 – BVernon 2016-07-05 16:20:12