I have a model
public class Shop()
{
public string ArticleName {get; set;}
public int ArticleTotalCount {get; set;}
public List<Package> Package {get; set;}
}
with list of objects
public class Package()
{
public int Count {get; set;}
public decimal Price {get; set;}
}
My view:
@model Shop
@Html.LabelFor(x => Model.ArticleName)
@Html.EditorFor(x => Model.ArticleName)
@Html.LabelFor(x => Model.ArticleCount)
@Html.EditorFor(x => Model.ArticleCount)
<div id="sections">
<div class="section row">
<div class="col-md-4">
@Html.TextBox("count", null, new { @value = "", @class = "col-md-10" })
</div>
<div class="col-md-4">
@Html.TextBox("price", null, new { @value = "", @class = "col-md-10" })
</div>
</div>
</div>
<div class="row">
<input id='addsection' type="submit" value="Add new" />
</div>
<div class="row">
<input id='create' type="submit" value="Save" />
</div>
and script which create form after button.click()
<script>
var template = $('#sections .section:first').clone();
var sectionsCount = 1;
$('body').on('click', '#addsection', function() {
sectionsCount++;
var section = template.clone().find(':input').each(function(){
var newId = this.id + sectionsCount;
$(this).prev().attr('for', newId);
this.id = newId;
}).end()
.appendTo('#sections');
return false;
});
$("#create").click(function () {
$.ajax({
type: "POST",
url: '@Url.Action("AddArticles", "Shop")',
??????
??????
??????
});
});
In the view I want to: - fill name and count of article - dynamically create form(Count/Price) - sent everything after click on button I am trying do it by $.ajax by I do not know how.