具有100行List的MVC POST操作很慢(性能)
本文关键字:性能 操作 POST 100行 List MVC 具有 | 更新日期: 2023-09-27 17:57:31
目前正在ASP.NET-MVC5项目中工作。
我有一个型号为list
的View
。我的[HttpPost]
控制器大概用了5秒钟。有什么可能有助于性能的想法吗?或者这在MVC中是正常的吗?
我的观点:
@model list<TempViewModel>
......
<table border="1">
<thead>
<tr>
<td>Action Menu</td>
<td>Controller Name</td>
<td>Category</td>
<td>Group Desc</td>
</tr>
</thead>
@{
for(int x = 0;counter < model.count-1;counter++){
}
<tr>
<td>
@Html.TextBoxFor(m => m[x].ActionName)
@Html.ValidationMessageFor(m => m[x].ActionName)
</td>
<td>
@Html.TextBoxFor(m => m[x].ControllerName)
@Html.ValidationMessageFor(m => m[x].ControllerName)
</td>
<td>
@Html.TextBoxFor(m => m[x].Category)
@Html.ValidationMessageFor(m => m[x].Category)
</td>
<td>
@Html.TextBoxFor(m => m[x].GroupDesc)
@Html.ValidationMessageFor(m => m[x].GroupDesc)
</td>
</tr>
.....
<input type="submit" />
我的型号:
public class TempViewModel
{
[Required]
public string ActionName { get; set; }
[Required]
public string ControllerName { get; set; }
[Required]
public char Category { get; set; }
[Required]
public string GroupDesc { get; set; }
}
我的控制器:
[HttpPost]
public ActionResult SyncActionMenu(List<TempViewModel> model)
{
//do something with model here
}
如果您在看到验证错误之前说页面冻结,这意味着您不引人注目的jquery验证要做很多工作。
您可以禁用它。或者将可编辑行的数量减少到<50.
如果禁用它,您仍然可以通过检查ModelState.IsValid
并返回模型来检查控制器后期操作中的模型有效状态。