2011-05-03 81 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