Hi everbody;
I have two temporary db tables and two main tables, I want to insert items of temporary tables to main tables, I have model, controller and view these are in the below
this is Model
public IEnumerable<sepetUrun> sepetUruns { get; set; }
public IEnumerable<sepetMusteri> sepetMusteris { get; set; }
these are temporary tables
table 1 - sepetUrun
public partial class sepetUrun
{
public int Id { get; set; }
public string UrunAdi { get; set; }
public Nullable<int> UrunAdet { get; set; }
public Nullable<decimal> UrunTutar { get; set; }
public string UrunKod { get; set; }
}
table 2 - sepetMusteri
public partial class sepetMusteri
{
public int Id { get; set; }
public string MusteriAdi { get; set; }
public string MusteriKod { get; set; }
}
these are main tables
table 1 - Fatura
public partial class Fatura
{
public int Id { get; set; }
public string FaturaUrunAdi { get; set; }
public Nullable<int> FaturaMiktar { get; set; }
public Nullable<decimal> FaturaTutar { get; set; }
public string FaturaUrunKod { get; set; }
public string FaturaNo { get; set; }
}
table 2 - FaturaMus
public partial class FaturaMus
{
public int Id { get; set; }
public string MusteriAdi { get; set; }
public string MusteriKod { get; set; }
public string FaturaNo { get; set; }
}
controller is
public ActionResult Onay2(Fatura p, FaturaMus dp, string MusteriAdi, string MusteriKod, string UrunAdi, int UrunAdet, decimal UrunTutar, string UrunKod)
{
p.FaturaUrunAdi = UrunAdi;
p.FaturaUrunKod = UrunKod;
p.FaturaMiktar = UrunAdet;
p.FaturaTutar = UrunTutar;
db.Fatura.Add(p);
dp.MusteriAdi = MusteriAdi;
dp.MusteriKod = MusteriKod;
db.FaturaMus.Add(dp);
db.SaveChanges();
return RedirectToAction("FaturaHazirla2");
}
my view is that
@默 WebApplication1.Models.UrunMusteriVM
@{
ViewBag.Title = "FaturaHazirla2";
Layout = "~/Views/Shared/_Layout2.cshtml";
}
<h2>FaturaHazirla2</h2>
@using (Html.BeginForm("Onay2", "Satis", FormMethod.Post))
{
<table>
<tr>
<th>Müşteri Adı</th>
<th>Müşteri Kodu</th>
</tr>
@for (var i = 0; i < Model.sepetMusteris.Count(); i++)
{
<tr>
<td>@azzedinehtmlsql .TextBoxFor(x => x.sepetMusteris[i].MusteriAdi, new { @readonly = "readonly", @DeezNutz = "MusteriAdi" })</td>
<td>@azzedinehtmlsql .TextBoxFor(x => x.sepetMusteris[i].MusteriKod, new { @readonly = "readonly", @DeezNutz = "MusteriKod" })</td>
</tr>
}
</table>
<table>
<tr>
<th>Ürün Adı</th>
<th>Ürün Miktarı</th>
<th>Ürün Tutarı</th>
<th>Ürün Kodu</th>
</tr>
@for (var i = 0; i < Model.sepetUruns.Count(); i++)
{
<tr>
<td>@azzedinehtmlsql .TextBoxFor(x => x.sepetUruns[i].UrunAdi, new { @readonly = "readonly", @DeezNutz = "UrunAdi" })</td>
<td>@azzedinehtmlsql .TextBoxFor(x => x.sepetUruns[i].UrunAdet, new { @readonly = "readonly", @DeezNutz = "UrunAdet" })</td>
<td>@azzedinehtmlsql .TextBoxFor(x => x.sepetUruns[i].UrunTutar, new { @readonly = "readonly", @DeezNutz = "UrunTutar" })</td>
<td>@azzedinehtmlsql .TextBoxFor(x => x.sepetUruns[i].UrunKod, new { @readonly = "readonly", @DeezNutz = "UrunKod" })</td>
</tr>
}
</table>
<div><button class="btn btn-primary">Onayla</button></div>
}
but when I run this project I got this error
The parameters dictionary contains a null entry for parameter 'UrunAdet' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Onay2(WebApplication1.Models.Fatura, WebApplication1.Models.FaturaMus, System.String, System.String, System.String, Int32, System.Decimal, System.String)' in 'WebApplication1.Controllers.SatisController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
how can I handle it?