Hi,
I need to draw two models in a view. Model 1 will register on the same page.
Model Article will record. Model 1 and 2 will be related to each other.
My goal is to save the database when I post the VMArtikel model.
How should we proceed in this case? Can you make an example?
View
@model Tuple<VM_Beyanname, VM_Artikel>
<div class="content-page">
<div class="content">
<!-- Start Content-->
<div class="container-fluid">
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box">
@*<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="javascript: void(0);">Abstack</a></li>
<li class="breadcrumb-item"><a href="javascript: void(0);">Forms</a></li>
<li class="breadcrumb-item active">Form Wizard</li>
</ol>
</div>*@
<h4 class="page-title">Beyanname Ekle</h4>
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">
<div class="card-box">
<form asp-controller="Beyanname" asp-action="BeyannameAdd">
<section>
<div class="form-group clearfix">
<label class="control-label">Beyanname NO *</label>
<div class="">
<input asp-for="Item1.BeyannameNO" class="form-control required" type="text">
</div>
</div>
<div class="form-group clearfix">
<label class="control-label"> Tarih *</label>
<div class="">
<input asp-for="Item1.Tarih" class="form-control" type="date">
</div>
</div>
</section>
<div class="form-group clearfix text-right">
<button type="submit" class="text-right btn btn-primary">Kaydet</button>
</div>
</form>
</div>
</div>
<div class="col-md-10">
<div class="card-box">
<form id="basic-form" asp-controller="Beyanname" asp-action="ArtikelAdd">
<div>
<h3>Beyanname</h3>
<section>
<div class="form-group clearfix">
<label class="control-label">Beyanname NO *</label>
<div class="">
<input value="@ViewBag.Bey" class="form-control required" name="bNO" type="text">
</div>
</div>
<div class="form-group clearfix">
<label class="control-label " for="password"> Sezon Kodu *</label>
<div class="">
<input asp-for="Item2.SezonKodu" type="text" class="required form-control">
</div>
</div>
<div class="form-group clearfix">
<label class="control-label " for="confirm">Artikel Kodu *</label>
<div class="">
<input asp-for="Item2.ArtikelKodu" type="text" class="required form-control">
</div>
</div>
</section>
<h3>Ürün</h3>
<section>
<div class="form-group clearfix">
<label class="control-label" for="name"> Kumas Kodu *</label>
<div class="">
<input asp-for="Item2.KumasKodu" type="text" class="required form-control">
</div>
</div>
<div class="form-group clearfix">
<label class="control-label " for="surname">Icerik Bilgisi *</label>
<div class="">
<input asp-for="Item2.IcerikBilgisi" type="text" class="required form-control">
</div>
</div>
<div class="form-group clearfix">
<label class="control-label " for="email">GTip *</label>
<div class="">
<input asp-for="Item2.Gtip" name="email" type="text" class="required email form-control">
</div>
</div>
<div class="form-group clearfix">
<label class="control-label " for="address">Kalem Sayısı *</label>
<div class="">
<input asp-for="Item2.KalemSayisi" name="address" type="text" class="form-control">
</div>
</div>
</section>
<h3>Ağırlık</h3>
<section>
<div class="form-group clearfix">
<label class="control-label" for="name"> Adet *</label>
<div class="">
<input asp-for="Item2.Adet" type="text" class="required form-control">
</div>
</div>
<div class="form-group clearfix">
<label class="control-label " for="surname">Birim Fiyat *</label>
<div class="">
<input asp-for="Item2.BirimFiyat" type="text" class="required form-control">
</div>
</div>
<div class="form-group clearfix">
<label class="control-label " for="email">Brüt Kg *</label>
<div class="">
<input asp-for="Item2.BrutKg" type="text" class="required email form-control">
</div>
</div>
<div class="form-group clearfix">
<label class="control-label " for="address">Net Kg *</label>
<div class="">
<input asp-for="Item2.NetKg" type="text" class="form-control">
</div>
</div>
</section>
<h3>Ürün Detay</h3>
<section>
<div class="form-group clearfix">
<label class="control-label" for="name"> Kap *</label>
<div class="">
<input asp-for="Item2.Kap" type="text" class="required form-control">
</div>
</div>
<div class="form-group clearfix">
<label class="control-label " for="surname">Ticari Tanım *</label>
<div class="">
<input asp-for="Item2.TicariTanim" type="text" class="required form-control">
</div>
</div>
<div class="form-group clearfix">
<label class="control-label " for="email">Cinsiyet Bilgisi *</label>
<div class="">
<input asp-for="Item2.CinsiyetBilgisi" type="text" class="required email form-control">
</div>
</div>
<div class="form-group clearfix">
<label class="control-label " for="address">Mensei Bilgisi *</label>
<div class="">
<input asp-for="Item2.MenseiBilgisi" type="text" class="form-control">
</div>
</div>
</section>
</div>
</form>
</div>
</div>
</div>
</div>
Controller
public IActionResult Index()
{
Beyanname beyanname = new Beyanname();
beyanname = _beyannameReadRepository.GetWhere(x => x.Tarih != null).OrderByDescending(x => x.Tarih).FirstOrDefault();
ViewBag.Bey = beyanname.BeyannameNO;
return View();
}
[HttpPost]
public async Task<IActionResult> ArtikelAdd([Bind(Prefix = "Item2")] VM_Artikel vM_Artikel)
{
Artikel artikel = new Artikel();
artikel = _mapper.Map<Artikel>(vM_Artikel);
artikel.BeyannameNO = bNO;
await _artikelWriteRepository.AddAsync(artikel);
await _artikelWriteRepository.SaveAsync();
TempData["Mesaj"] = "Artikel Kaydedildi";
return View();
}
CustomerModel
public class CustomerModel
{
public int CId { get; set; }
public string CName { get; set; }
}
PersonModel
public class PersonModel
{
public int PId { get; set; }
public string PName { get; set; }
public int CId { get; set; }
}