将子模型中的多个记录绑定到mvc中的父模型视图

时间:2017-04-26 17:24:07

标签: jquery asp.net-mvc razor asp.net-mvc-5

我有一个查询。我想将多个记录绑定到ModelView内的模型, 这样它就会根据父模型的Id插入记录。

这是我的代码

res.end('OK')


@model PathoWebApp.ModelViews.SubTestOnes
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
@using (Html.BeginForm("Create", "SubTests", FormMethod.Post, new { @id = "frmSubTestOnes" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <div class="row">
        <div class="col-sm-2">
            @Html.LabelFor(m => m.NormalRange)
        </div>
        <div class="col-sm-1">
            @Html.CheckBoxFor(m => m.NormalRangeB)
        </div>
        <div class="col-sm-9">
            <div class="form-group" id="divForNormalRange">
                <table class="table table-responsive" id="TestSample">
                    <tbody>

                    </tbody>
                </table>
            </div>
        </div>
    </div>
} 

ajax调用局部视图来获取具有按钮的Row,该按钮在表上创建多行,如下所示。 Image of view

当我想提交此记录时,它仅选择第一个记录模型。 请帮忙......

更新 父模型 SubTestOnes

<script type="text/javascript">
    $(function () {
        $('#NormalRangeB').change(function () {
            $.ajax({
                url: '/SubTests/GetNormalRange',
                type: 'GET',
                dataType: 'html',
                success: function (data) {
                    $('#TestSample').each(function () {
                        var tds = '<tr>';
                        tds += data;
                        tds += '</tr>';
                        if ($('tbody', this).length > 0) {
                            $('tbody', this).append(tds);
                        } else {
                            $(this).append(tds);
                        }
                    });
                }
            });
        });
    });
</script>

儿童模特 NormalRangeInfo

public class SubTestOnes
    {
        public Int64 Id { get; set; }
        [Display(Name = "Test")]
        public Nullable<Int64> TestId { get; set; }
        [Display(Name = "Sub Test")]
        public string SubTestName { get; set; }
        [Display(Name = "Test Unit")]
        public string TestUnit { get; set; }
        [Display(Name = "Normal Range")]
        public string NormalRange { get; set; }
        [Display(Name = "Dependent Sub Test One")]
        public string DependentSubTestOne { get; set; }
        public string DependentSubTestTwo { get; set; }
        [Display(Name = "Formula")]
        public string Formula { get; set; }
        public string DefaultValue { get; set; }
        public Nullable<int> Priority { get; set; }
        public string Heading { get; set; }
        public string Value { get; set; }
        public string Investigation { get; set; }
        public string Description { get; set; }
        public bool NormalRangeB { get; set; }
        public bool DependentSubTestOneB { get; set; }
        public bool DependentSubTestTwoB { get; set; }
        public bool InvestigationB { get; set; }
        public bool HeadingB { get; set; }
        public bool ValueB { get; set; }
        public List<Models.NormalRangeInfo> NormalRanges { get; set; }
    }

0 个答案:

没有答案
相关问题