I have a query. I want to bind multiple record to model which is inside ModelView, That way it'll insert record as per the Id of parent model.
here is my code
@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>
}
<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>
the ajax call the partial view to get Row that have button which create multiple rows on table which looks like this.
When I want to submit this record it selects only first Record In Model. Please Help...
Update Parent Model SubTestOnes
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; }
}
Child model NormalRangeInfo
public class NormalRangeInfo
{
[Key,DatabaseGenerated (DatabaseGeneratedOption.Identity)]
public Int64 NormalRangeID { get; set; }
[ForeignKey("SubTests")]
public Int64 SubtestID { get; set; }
public int? NormalMin { get; set; }
public int? NormalMax { get; set; }
public string NormalType { get; set; }
public string NormalAllowValue { get; set; }
public string Gender { get; set; }
public Nullable<decimal> AgeMin { get; set; }
public Nullable<decimal> AgeMax { get; set; }
public string AgeType { get; set; }
}