将视图表数据绑定到MVC模型

时间:2015-11-02 21:27:27

标签: javascript c# ajax asp.net-mvc-3 model-view-controller

我正在开发一个现有的项目,有人写了一个视图,并试图将表数据绑定到模型列表,它没有工作,我的技能不能解决为什么

继承人我认为应该设置绑定的javascript行

$("#benefitsTable").bindmvclist();

,这是视图中的表格

                                                              福利类型                         量                         到期日                     

                @* The insert template is only needed when the form is unlocked and therefore editable. *@
                @if (Model.IsUnlocked)
                {
                    <div data-type="itemtemplate" class="benefits-row">
                        @if (Model.CanEdit)
                        {
                            <input id="Benefits_{0}__AllowanceId" name="Benefits_[{0}].AllowanceID" type="hidden" value="0"/>
                            <select id="Benefits_{0}__AllowanceTypeId" name="Benefits[{0}].AllowanceTypeID" style="width: 220px">
                                @foreach (var allowance in Model.AllowanceTypesBenefits)
                                {
                                    <option value="@allowance.Value">@allowance.Text</option>
                                }
                            </select>
                            <input id="Benefits_{0}__AllowanceAmount" name="Benefits[{0}].Amount" type="text" value="" style="width: 68px;"/>
                            <input id="Benefits_{0}__ExpiryDate" name="Benefits[{0}].ExpiryDate" type="text" value="" class="datepickerrecurring datepicker" style="width: 80px"/>
                            <a class="removeBenefit" href="#"><i class="icon-close-delete"></i></a>
                        }
                        else if (Model.CanView)
                        {
                            <p>@Model.Benefits[0].AllowanceTypeName</p>
                        }
                    </div>
                }
                @if (Model.Benefits != null)
                {
                            @* Do not turn into a foreach. *@
                    for (var i = 0; i < Model.Benefits.Count(); i++)
                    {
                        <div class="benefits-row">
                            @Html.HiddenFor(a => Model.Benefits[i].AllowanceID) @* This somehow magically turns into id="Benefits_0__AllowanceTypeID" name="Benefits[0].AllowanceTypeID", which is why a foreach won't work. *@

                            @if (Model.IsUnlocked)
                            {
                                if (Model.CanEdit)
                                {
                                    @Html.DropDownListFor(a => Model.Benefits[i].AllowanceTypeID, new SelectList(Model.AllowanceTypesBenefits, "Value", "Text", Model.Benefits[i].AllowanceTypeID), new {@style = "width:220px;"}, Model.CanView)
                                    @Html.TextBoxFor(a => Model.Benefits[i].Amount, Model.CanView, new {maxlength = "100", size = "8", Value = String.Format("{0:0.00}", Model.Benefits[i].Amount)})
                                    @Html.ValidationMessageFor(m => Model.Benefits[i].Amount)

                                    @Html.TextBoxFor(a => Model.Benefits[i].ExpiryDate, new {@class = "datepicker", @style = "width: 80px;", Value = String.Format("{0:d/MM/yyyy}", Model.Benefits[i].ExpiryDate), @readonly = "readonly"})
                                    @Html.ValidationMessageFor(m => Model.Benefits[i].ExpiryDate)
                                    <a class="removeBenefit" href="#"><i class="icon-close-delete"></i></a>
                                }
                                else if (Model.CanView)
                                {
                                    <span class="benefitLabel">@Model.Benefits[i].AllowanceTypeName</span>
                                    @Html.TextBoxFor(a => Model.Benefits[i].Amount, Model.CanView, new {maxlength = "100", size = "8", Value = String.Format("{0:0.00}", Model.Benefits[i].Amount), @readonly = "readonly", disabled = "disabled"})
                                    @Html.TextBoxFor(a => Model.Benefits[i].ExpiryDate, new {@style = "width: 80px;", Value = String.Format("{0:d/MM/yyyy}", Model.Benefits[i].ExpiryDate), @readonly = "readonly", disabled = "disabled"})
                                }
                            }
                            else
                            {
                                <span class="benefitLabel">@Model.Benefits[i].AllowanceTypeName</span>
                                <input type="text" size="8" value="###" disabled="disabled"/>
                                @Html.TextBoxFor(a => Model.Benefits[i].ExpiryDate, new {@class = "datepicker", @style = "width: 80px;", Value = String.Format("{0:d/MM/yyyy}", Model.Benefits[i].ExpiryDate), @readonly = "readonly", disabled = "disabled"})

                            }
                        </div>
                    }
                }
            </div>
        </fieldset>

非常感谢任何帮助/指导:)

注意:加载页面时,控制台会记录以下错误:&#34;未捕获TypeError:$(...)。bindmvclist不是函数&#34;

0 个答案:

没有答案