0

是的,我们有一个标准表单,可以将模型发布到端点并保存/更新数据库中的数据。在本地,表单每次都有效并更新模型,从而更新数据库。然而,在生产服务器上,保存是间歇性的,有时有效,有时无效。当它失败时,页面会重新加载新添加的数据,但在页面的额外 GET 请求后,旧数据会再次显示。

我已经在各个点记录了 POST 数据,即使发送失败,所需的所有内容也会发送到端点。我能理解的是为什么有时它会保存,有时它不会。

使用:MS Windows Server 2012、ASP.NET MVC 4、IIS 7.5

相当坚持在哪里寻找下一步以追踪问题?任何帮助追踪问题将不胜感激!

这是有问题的表格:

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    <div class="form-row" style="margin-top: 60px;">
        @Html.LabelFor(m => m.FirstName)
        @Html.EditorFor(m => m.FirstName, Model.FirstName)
        @Html.ValidationMessageFor(m => m.FirstName)
    </div>
    <div class="form-row">
        @Html.LabelFor(m => m.LastName)
        @Html.EditorFor(m => m.LastName, Model.LastName)
        @Html.ValidationMessageFor(m => m.LastName)
    </div>
    <div class="form-row">
        @Html.LabelFor(m => m.DateOfBirth)
        @Html.EditorFor(m => m.DateOfBirth, Model.DateOfBirth)
        @Html.ValidationMessageFor(m => m.DateOfBirth)
    </div>
    <div class="form-row bottom-line">
        @Html.LabelFor(m => m.Gender)
        @Html.RadioButtonForEnum(m => m.Gender, "gender-wrapper")
    </div>
    <div class="form-row">
        @Html.LabelFor(m => m.Headline)
        @Html.EditorFor(m => m.Headline, Model.Headline)
        @Html.ValidationMessageFor(m => m.Headline)
    </div>
    <div class="form-row">
        @Html.LabelFor(m => m.Industry)
        @Html.DropDownListFor(m => m.Industry, (SelectList)ViewBag.Industries, new { @class = "industry-select" })
        @Html.ValidationMessageFor(m => m.Industry)
    </div>
    <div class="form-row">
        @Html.LabelFor(m => m.Position)
        @Html.EditorFor(m => m.Position)
    </div>
    <input type="submit" value="save" />
    }

和端点:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Settings([ModelBinder(typeof(DateTimeModelBinder))]UserSettingsViewModel model)
{
    var user = userService.LoadUser(User.UserId);
    ViewBag.Industries = new SelectList(userService.GetAllIndustries(), "Name", "Name", user.Industry);

    if (ModelState.IsValid)
    {
        Mapper.Map(model, user);
        userService.UpdateUser(user);
        model = Mapper.Map<User, UserSettingsViewModel>(user);
    }
    else //leave the model intack to correct errors, just set the other tab data
    {
        model.Education = Mapper.Map<IList<UserEducation>, IList<EducationViewModel>>(user.UserEducations.ToList());
        model.Employment = Mapper.Map<IList<UserEmployment>, IList<EmploymentViewModel>>(user.UserEmployments.ToList());
    }
    return View(model);
}

还有一个自定义模型绑定器,用于从日、月、年下拉列表中创建日期时间,以及用于日期时间类型的自定义编辑器。如果需要也可以显示这些。

4

1 回答 1

0

我看到的问题是,现在您遇到了 N 层系统的问题,但您不知道问题存在于哪一层。我要做的第一件事是在数据库上启动 SQL 分析器并在问题发生时运行跟踪。如果在发生故障时您没有看到任何通信,那么这很好,因为您可能已经消除了 50% 的潜在问题并且可以专注于 mvc 应用程序。

另一方面,如果数据在所有情况下都以相同的方式发送到数据库,那么您就知道问题出在您的数据库代码上。

于 2013-09-27T21:03:06.017 回答