My understanding is that you would like to add multiple Raws when you create an offer, and then pass all data to your controller.It could be done with the help of js. You could refer to my simple demo below.
1.My Models
public class OfferRawCreateViewModel
{
public string PartCode { get; set; }
public string PartDescription { get; set; }
}
public class OfferCreateViewModel
{
public OfferCreateViewModel()
{
this.Raws = new List<OfferRawCreateViewModel>();
}
public string CarModel { get; set; }
public string CarOwner { get; set; }
public ICollection<OfferRawCreateViewModel> Raws { get; set; }
}
2. View
@model WebApplication1.Models.OfferCreateViewModel
<form asp-action="Create" method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="CarModel" class="control-label"></label>
<input asp-for="CarModel" class="form-control" />
<span asp-validation-for="CarModel" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="CarOwner" class="control-label"></label>
<input asp-for="CarOwner" class="form-control" />
<span asp-validation-for="CarOwner" class="text-danger"></span>
</div>
<div class="form-group" id="item-list">
<a href="#" id="add">Add</a>
<br />
<input type="text" asp-for="Raws" class="items" name="Raws[0].PartCode" />
<input type="text" asp-for="Raws" class="items" name="Raws[0].PartDescription" />
</div>
<input type="submit" value="Create" class="btn btn-default" />
</form>
@section Scripts {
<script>
$(function () {
$("#add").click(function (e) {
e.preventDefault();
var i = ($(".items").length) / 2;
var n = '<br /><input type="text" class="items" name="Raws[' + i + '].PartCode" />' +
'<input type="text" class="items" name="Raws[' + i + '].PartDescription" />'
$("#item-list").append(n);
});
});
</script>
}
3.Controller
[HttpPost]
public async Task<IActionResult> Create(OfferCreateViewModel model)