Asp.net MVC 2를 사용중인 최근 프로젝트에서 DisplayFor에 성능 문제가 있음을 발견했습니다. 나는 그것이 진짜 문제인지 또는 무엇인가 놓친 것이 확실하지 않은가?Asp.net MVC 2 DisplayFor 성능 문제?
나는 Asp.net MVC 전문가가 나에게 설명해주기를 바란다. :)
모델.
public class Customer
{
public int CustomerId { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string EmailAddress { get; set; }
public static IEnumerable<Customer> GetCustomers()
{
for (int i = 0; i < 1000; i++)
{
var cust = new Customer()
{
CustomerId = i + 1,
Name = "Name - " + (i + 1),
Address = "Somewhere in the Earth...",
EmailAddress = "customerABC"
};
yield return cust;
}
}
}
컨트롤러
public ActionResult V1()
{
return View(Customer.GetCustomers());
}
public ActionResult V2()
{
return View(Customer.GetCustomers());
}
V1
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Customer>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
V1
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>V1</h2>
<table>
<%foreach (var cust in this.Model)
{%>
<%= Html.DisplayFor(m => cust) %>
<%} %>
</table>
</asp:Content>
그리고 템플릿
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Customer>" %>
<tr>
<td><%= this.Model.CustomerId %></td>
<td><%= this.Model.Name %></td>
<td><%= this.Model.Address %></td>
<td><%= this.Model.EmailAddress %></td>
</tr>
V2 (NO 성능 문제)
입니다 (성능 문제를 갖고있는)3210<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Customer>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
V2
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>V2</h2>
<table>
<%foreach (var cust in this.Model)
{%>
<tr>
<td><%= cust.CustomerId%></td>
<td><%= cust.Name%></td>
<td><%= cust.Address%></td>
<td><%= cust.EmailAddress%></td>
</tr>
<%} %>
</table>
</asp:Content>
V1과 V2의 성능 차이를 쉽게 볼 수 있습니다.
EDIT : 내 로컬 IIS 7 (릴리스 버전 포함)에 배포하면 (V1) 매우 빠르게됩니다. 문제는 해결되었지만 여전히 그 이유를 알고 싶습니다. :)
감사
SOE 모에
감사합니다! 디버그를 false로 전환했으며 성능이 예상대로 되돌아갔습니다 ... – bytebender