具有100行List的MVC POST操作很慢(性能)

时间:2015-06-22 04:30:28

标签: c# asp.net-mvc

目前正致力于ASP.NET-MVC5项目。

我有View list作为模型。点击我的[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
}

1 个答案:

答案 0 :(得分:0)

如果你在看到验证错误之前说过页面冻结,这意味着你不引人注目的jquery验证会做很多工作。

你可以禁用它。或者将可编辑行的数量减少到&lt; 50。

如果您禁用它,您仍然可以通过选中ModelState.IsValid并返回模型来检查控制器发布操作中的模型有效状态。