【发布时间】:2022-01-19 15:23:16
【问题描述】:
我想将项目从一个数据库表复制到另一个表,我有模型,两个数据库表,但是当我运行视图时出现错误,在下面我的模型、表和控制器和视图中,
我的模型是
public IEnumerable<sepetUrun> sepetUruns { get; set; }
public IEnumerable<sepetMusteri> sepetMusteris { get; set; }
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; }
sepetMusteri 数据库是
public int Id { get; set; }
public string MusteriAdi { get; set; }
public string MusteriKod { get; set; }
我的控制器是
public ActionResult FaturaHazirla2()
{
UrunMusteriVM urunMusteriVM = new UrunMusteriVM();
urunMusteriVM.sepetUruns = db.sepetUrun.ToList();
urunMusteriVM.sepetMusteris = db.sepetMusteri.ToList();
return View(urunMusteriVM);
}
public ActionResult Onay2(FaturaMus p, Fatura dp, string MusteriAdi, string MusteriKod, string UrunAdi, int UrunAdet, decimal UrunTutar, string UrunKod)
{
p.MusteriAdi = MusteriAdi;
p.MusteriKod = MusteriKod;
dp.FaturaUrunAdi = UrunAdi;
dp.FaturaMiktar = UrunAdet;
dp.FaturaTutar = UrunTutar;
dp.FaturaUrunKod = UrunKod;
db.FaturaMus.Add(p);
db.Fatura.Add(dp);
db.SaveChanges();
return View("FaturaHazirla2");
}
我的看法是
<form action="/Satis/Onay2/">
<table>
<tr>
<th>Müşteri Adı</th>
<th>Müşteri Kodu</th>
</tr>
@foreach (var item in Model.sepetMusteris)
{
<tr>
<td>@Html.TextBoxFor(x => item.MusteriAdi, new { @readonly = "readonly", name = "MusteriAdi2" })</td>
<td>@Html.TextBoxFor(x => item.MusteriKod, new { @readonly = "readonly", name = "MusteriKod2" })</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>
@foreach (var item in Model.sepetUruns)
{
<tr>
<td>@Html.TextBoxFor(x => item.UrunAdi, new { @readonly = "readonly" })</td>
<td>@Html.TextBoxFor(x => item.UrunAdet, new { @readonly = "readonly" })</td>
<td>@Html.TextBoxFor(x => item.UrunTutar, new { @readonly = "readonly" })</td>
<td>@Html.TextBoxFor(x => item.UrunKod, new { @readonly = "readonly" })</td>
</tr>
}
</table>
<div><button class="btn btn-primary">Onayla</button></div>
</form>
但是当我运行它时,我得到了这个错误
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.FaturaMus, WebApplication1.Models.Fatura, 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.
我该如何解决这个问题
【问题讨论】:
标签: asp.net model-view-controller entity