我的 ASP.NET MVC Web 应用程序出现问题,ViewModel
当表单发布时,我需要大约 30 秒才能点击我的控制器。因此,我猜这与默认的模型绑定器有关。
[HttpPost]
public ActionResult Edit(ByActivityEditViewModel viewModel)
{
if (ModelState.IsValid) // Takes ~30 seconds before even hitting this
{
MyView
是一系列嵌套的Group
父母和User
孩子的复选框。相同的User
可能会列在多个Groups
. 我正在使用 anEditorFor
为ViewModel
.
视图的编辑器模板调用: @Html.EditorFor(model => model.Groups)
编辑器模板:
@model MyProject.Models.Group
@Html.HiddenFor(model => model.Guid)
@Html.HiddenFor(model => model.Name)
@Html.CheckBoxFor(model => model.IsAllowed, new { @class = Model.Guid.ToString(), @style = "margin-right:5px; cursor:pointer;" }) @Html.LabelFor(model => model.IsAllowed, Model.Name, new { @class = "build-checkbox-label", @style = "font-weight:normal; margin-top:-2px;" })
@if (Model.Users.Any())
{
<ul style="list-style:none;">
@for (int i = 0; i < Model.Users.Count; i++)
{
<li>
@Html.HiddenFor(model => Model.Users[i].Guid)
@Html.HiddenFor(model => Model.Users[i].Name)
@Html.CheckBoxFor(model => Model.Users[i].IsAllowed, new { @class = Model.Users[i].Guid.ToString(), @style = "margin-right:5px; cursor:pointer;" }) @Html.LabelFor(model => Model.Users[i].IsAllowed, Model.Users[i].Name, new { @class = "build-checkbox-label", @style = "font-weight:normal; margin-top:-2px;" })
</li>
}
</ul>
}
视图模型:
public class ByActivityEditViewModel
{
public int ActivityId { get; set; }
public string Path { get; set; }
public IList<Group> Groups { get; set; } = new List<Group>();
}
public class Group
{
public Guid? Guid { get; set; }
public string Name { get; set; }
public string DistinguishedName { get; set; }
public string SamAccountName { get; set; }
public string DisplayName { get; set; }
public bool IsAllowed { get; set; }
public List<User> Users { get; set; } = new List<User>();
}
public class User
{
public Guid? Guid { get; set; }
public string Name { get; set; }
public string DistinguishedName { get; set; }
public string SamAccountName { get; set; }
public string DisplayName { get; set; }
public bool IsAllowed { get; set; }
public bool IsUserChecked { get; set; }
}
模型状态:
模型状态包含 Guids、Names 和 IsAllowed 值。我相信处理这是缓慢的部分。
结果是:
用户可以属于多个组。
我试过了:
任何建议、信息或解决方法将不胜感激。
在处理大量控件时,Jquery/js 函数之前已经为我做过几次了,我一直在想办法弄清楚。现在我知道先看哪里了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句