RowVersion值未绑定到表单数据mvc 5

时间:2018-07-16 05:27:53

标签: asp.net-mvc entity-framework concurrency optimistic-concurrency rowversion

我正在尝试在MVC 5中使用EF6实现并发。

 @Html.HiddenFor(model => model.RowVersion)

在我的编辑页面上,我可以看到输入类型中的rowversion值处于隐藏状态。

 <input id="RowVersion" name="RowVersion" type="hidden" value="AAAAAAAAF3M=">

但是在$('form')。serializeArray()上,我没有获取RowVersion数据,在发布表单时,我也没有得到RowVersion属性的空值。

我后来在数据库表中添加了RowVersion列,然后更新了edmx,我将并发模式设置为在edmx中的表的主键列属性中固定。

行版本是否还有其他需要做的事情? 任何帮助将不胜感激。

更新:添加html代码

jQuery:我正在使用$('form')。serializeArray()

在控制台中对其进行检查

来自浏览器的html输出:

        <form action="/Master/EditBookMaster/13" method="post"><input name="__RequestVerificationToken" type="hidden" value="Y04ae_LHgfG9Tw9hy2TcHIYbxk_EX_vykyphV7Sm9Wwiz6_f8PpGUY2SULyiZbCdJv4fgBloOlx_QRUz1FQNvXTZUorLt6_EvA9XLxcFsxbQqUlmY9XOCduHa__q1kdRQJpFAx4wOuj5tRu48TLh9A2" />    <div class="form-horizontal">
                <h4>BookMaster</h4>
                <hr />

                <input data-val="true" data-val-number="The field BookMasterId must be a number." data-val-required="The BookMasterId field is required." id="BookMasterId" name="BookMasterId" type="hidden" value="13" />

                <div class="form-group">
                    <label class="control-label col-md-2" for="BookName">BookName</label>
                    <div class="col-md-10">
                        <input class="form-control text-box single-line" id="BookName" name="BookName" type="text" value="C Programming" />
                        <span class="field-validation-valid text-danger" data-valmsg-for="BookName" data-valmsg-replace="true"></span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label col-md-2" for="Count">Count</label>
                    <div class="col-md-10">
                        <input class="form-control text-box single-line" data-val="true" data-val-number="The field Count must be a number." data-val-required="The Count field is required." id="Count" name="Count" type="number" value="10" />
                        <span class="field-validation-valid text-danger" data-valmsg-for="Count" data-valmsg-replace="true"></span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label col-md-2" for="Publisher">Publisher</label>
                    <div class="col-md-10">
                        <input class="form-control text-box single-line" id="Publisher" name="Publisher" type="text" value="Dennis-Ritchie" />
                        <span class="field-validation-valid text-danger" data-valmsg-for="Publisher" data-valmsg-replace="true"></span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label col-md-2" for="Subject">Subject</label>
                    <div class="col-md-10">
                        <select class="form-control text-box single-line" data-val="true" data-val-number="The field SubjectId must be a number." data-val-required="The SubjectId field is required." id="SubjectId" name="SubjectId"><option value="1">Fiction</option>
        <option value="2">Biography</option>
        <option value="3">Science</option>
        <option value="4">Research</option>
        <option selected="selected" value="5">Software developement</option>
        </select>
                        <span class="field-validation-valid text-danger" data-valmsg-for="SubjectId" data-valmsg-replace="true"></span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label col-md-2" for="AvailableCount">AvailableCount</label>
                    <div class="col-md-10">
                        <input class="form-control text-box single-line" data-val="true" data-val-number="The field AvailableCount must be a number." id="AvailableCount" name="AvailableCount" type="number" value="8" />
                        <span class="field-validation-valid text-danger" data-valmsg-for="AvailableCount" data-valmsg-replace="true"></span>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <input type="submit" value="Save" class="btn btn-default" />
                    </div>
                </div>
            </div>
        </form>
  <div>
 <a href="/Master/Index">Back to List</a>
  </div>
  <input id="RowVersion" name="RowVersion" type="hidden" value="AAAAAAAAF3M=" />

1 个答案:

答案 0 :(得分:2)

$(":input,:hidden").serialize();

代码代替

$('form').serializeArray()

Click here to view preview.