gpt4 book ai didi

asp.net-mvc - 渲染 View 需要很长时间

转载 作者:行者123 更新时间:2023-12-04 20:02:32 28 4
gpt4 key购买 nike

我们有一个 MVC 4 Web 应用程序。我使用 miniprofiler 来检查它花费了多长时间,它表明渲染具有三个局部 View 的 View 花费了很长时间。我尝试将部分 View 中的信息直接移动到页面上,这在时间上没有任何区别。我应该怎么做才能减少渲染时间?关于我应该从哪里开始寻找的任何提示?如您所见,渲染耗时 48 秒。

                                         **| duration | from start(ms)**
|http://localhost:61380/CaseContacts | 653.7 | +0.0
|Controller: CaseController.Contacts | 11.9 | +641.1
| Contacts view - not an ajax request | 0.3 | +651.7
| populating view model | 0.0 | +652.1
| getting list of contacts | 374.4 | +652.1
| Find: Contacts | 499.8 | +1033.6
| Render: Contacts | 48400.8 | +1535.2

**| client event |duration(ms)| from start(ms)**
|Request start | | +2.0
|Response | 1.0 | +52245.0
|Dom loading | | +52247.0
|scripts | 390.0 | +52315.0
|Dom Content Loaded Event| 29.0 | +52707.0
|Dom Interactive | | + 52707.0
|Load Event | | + 52760.0
|Dom Complete | | + 52760.0

更新:

public IQueryable<T> FindQueryable(Expression<Func<T, bool>> predicate, Func<T, Object> orderBy)
{
return this.db.GetAll<T>().Where(predicate).OrderBy(orderBy).AsQueryable<T>();
}
public class ContactRepository : Repository<USRContact>, IContactRepository<USRContact>
{
public IList<ContactNameViewModel> GetAll(int fieldOfficeID, string searchText = "")
{
if (searchText.Length > 0)
return Mapper.Map<IList<USRContact>, IList<ContactNameViewModel>>(this.FindQueryable(x => (x.FieldOfficeID == fieldOfficeID) &&
(x.FormalName.Contains(searchText) || x.PreferredName.Contains(searchText) || x.Alias.Contains(searchText) || x.Pseudonym.Contains(searchText)), x => (x.STMGender.Gender)).ToList());
else
return Mapper.Map<IList<USRContact>, IList<ContactNameViewModel>>(this.FindQueryable(x => (x.FieldOfficeID == fieldOfficeID)).ToList());
}

然后我的 Controller 将结果加载到 View 模型上,然后:

@Html.Partial("~/Views/Shared/Contacts/ContactNameList.cshtml", Model.Contacts)

部分 View 包含以下代码:

@model IList<Casenator.Web.Models.Contact.ContactNameViewModel>
<ul id="NameList" style="margin-left:0">
@foreach (var item in Model)
{
@*<li>@Html.RouteLink(@item.FullName, "Contacts", new { id = item.ContactID })</li>*@
<li>@Ajax.RouteLink(item.FullName, "Contacts", new { id = item.ContactID }, new AjaxOptions { UpdateTargetId = "BasicInfo", OnSuccess="InitializeComboBoxes", OnBegin="LoadContact(" + item.ContactID + ")" }) </li>
}
</ul>

任何帮助将不胜感激!谢谢,萨弗里斯

最佳答案

您从查询中返回的内容很重要。如果你返回的是IEnumerable,最好返回IQueryable。你可能会看到 this质疑它可能对您的情况有帮助

我不认为像automapper 这样的工具是为映射许多记录而设计的。您可以尝试手动映射对象

关于asp.net-mvc - 渲染 View 需要很长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15211334/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com