0
using (Ajax.BeginForm("SaveTimeShift", new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "recordList", InsertionMode = InsertionMode.Replace }))

为什么当我在上面使用这个重载的 Ajax.BeginForm 构造函数时,我在我的模型中获得了更新的数据,但是当我在下面使用这个重载的构造函数时,我没有得到我的模型的更新值?我需要下面的构造函数才能设置表单的 html 类属性...

  using (Ajax.BeginForm("SaveTimeShift", @Model, new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "recordList", InsertionMode = InsertionMode.Replace }, new { @class = "form-inline" }))
            {


        @Html.TextBoxFor(model => model.StartDate, new { id = "startDate", @readonly = true, width = "100px" })
        @Html.HiddenFor(model => model.SelectedName, new { id = "selectedName" });
        @Html.HiddenFor(model => model.SelectedUserId, new { id = "selectedUserId" });



        <input class="btn btn-primary pull-right" type="submit" value="Save Time Shift" />
        }
4

1 回答 1

1

第二个Ajax.BeginForm()具有以下方法签名:

public static MvcForm BeginForm(this AjaxHelper ajaxHelper, string actionName, Object routeValues, AjaxOptions ajaxOptions, Object htmlAttributes)

您尝试@Model作为路由值传递,这不是模型绑定的工作方式。模型绑定器将通过发布的表单值构造您的复杂模型对象。将您的Ajax.BeginForm()方法更改为以下应该可以解决您的问题:

@using (Ajax.BeginForm("SaveTimeShift", new { }, new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "recordList", InsertionMode = InsertionMode.Replace }, new { @class = "form-inline" }))
{
    // Your textboxes, etc corresponding to your model properties go here
}
于 2012-11-19T08:35:35.497 回答