私はEditApplicationConcessionModel
ビューモデルからビューを持っている必要ですMVC検証:リストに1つの要素が含まれている場合、必須ではありません。それはより多くを持っている場合 - その後、彼らはすべてが
ListAnexes
public List<Anexes> ListAnexes { get; set; }
を持ってAnexes
クラスです
public class Anexes
{
[Display(Name = "Number", ResourceType = typeof(Resources.Resources))]
public string ContractAnexesNumber { get; set; }
[Display(Name = "Date", ResourceType = typeof(Resources.Resources))]
public string ContractAnexDate { get; set; }
}
SO私の見解で、私は附属書のリストを反復処理し、時間と数0を示す部分図_Anexes
をレンダリングF別館ここ
<div id="divAnexes">
@foreach (var item in Model.ListAnexes)
{
l.RenderPartial("_Anexes", item);
}
</div>
<div>
<button class="btn btn-primary" type="button" id="addAnex">ADD</button>
</div>
あなたは、私がボタンaddAnnexを持っていて、それをクリックしたときに、私はAddAnex
アクションにAJAXリクエストを作成し、ちょうどその部分図を追加していることがわかり、私の部分図_Anexes
@model MEMineralResources.Common.Entities.Anexes
@using (Html.BeginCollectionItem("ListAnexes"))
{
<div class="divAnex">
<div class="form-group">
@Html.LabelFor(m => m.ContractAnexesNumber, new { @class = "control-label" })
@Html.TextBoxFor(m => m.ContractAnexesNumber, new { @class = "form-control" })
@Html.LabelFor(m => m.ContractAnexDate, new { @class = "control-label" })
@Html.TextBoxFor(m => m.ContractAnexDate, new { @class = "form-control datepicker" })
<div id="linkDelte"></div>
</div>
</div>
}
ある_Anexes
(アクションが返す)を別の附属書と一緒にdivに追加します(したがって、データと別の附属書番号を記入することができます)
$('#addAnex').on('click', function() {
$.ajax({
async: false,
url: '@Url.Action("AddAnex", "Application")'
}).success(function (partialView) {
$('#divAnexes').append(partialView);
});
});
ここにAddAnnex
アクション
public ActionResult AddAnex()
{
Anexes anex = new Anexes();
return PartialView("_Anexes", anex);
}
問題がされている:リストは一つだけAnexes
の項目が含まれている場合 - それは数だと日付は義務ではありません。しかし、明らかに[追加]ボタンをクリックすると、別館の番号と日付の両方を記入する必要があります。そして、私はこの場合