我正在努力建立一个店面。
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。以下是StoreController中的Index代码:
[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);
以下是一些截图,一个显示错误,另一个显示显示的内容。
答案 0 :(得分:5)
就错误而言,你所显示的代码是错误的,因此无法回答它为什么会发生(尽管错误信息似乎不仅仅是自我解释)。就垃圾字符而言,它们是由您在操作中使用的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");
}