i am having a problem running this project : i have a table for my products and in the same page i can to press on "add" button and i will have a small window to add my new product .. this is my controller:
public class HomeController : Controller
{
CountingEntities hsb = new CountingEntities();
public ActionResult ProductTable()
{
var product = hsb.HesapTemels.ToList();
List<HesapTemel> yardimci = hsb.HesapTemels.ToList();
ViewBag.Funds = yardimci;
return View(product);
}
[HttpPost]
public ActionResult ProductTable(HesapTemel p)
{
try
{
HesapTemel _he = new HesapTemel();
_he.HesapAdi = p.HesapAdi;
_he.HesapKodu = p.HesapKodu;
_he.HesaptipiID = p.HesaptipiID;
hsb.HesapTemels.Add(_he);
hsb.SaveChanges();
return RedirectToAction("HesapTable", "Home");
}
catch (Exception ex)
{
throw new Exception("an error happened" + ex.Message);
}
}
and this is my view:
<div>
<a class="btn btn-success" data-toggle="modal" data-target=".bootstrapmodal">
<span class="glyphicon glyphicon-eye-open">
</span>Add
</a>
<div class="modal fade bootstrapmodal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header"></div>
<div class="modal-body">
@Html.Partial("_partial.cshtml");
</div>
<div class="modal-footer"></div>
</div>
</div>
</div>
<div>
<table style="width: 100%;">
<thead>
<tr>
<th>id</th>
<th>hesap kodu</th>
<th>hesap adı</th>
<th>hesap tipi</th>
</tr>
</thead>
<tbody>
@foreach (var item in ViewBag.Funds)
{
<tr>
<td>@item.ID</td>
<td>@item.HesapKodu</td>
<td>@item.HesapAdi</td>
<td>@item.Hesaptipi.Harf</td>
</tr>
}
</tbody>
</table>
</div>
and this is my partial view :
@model WebApplication7.Models.HesapTemel
@using (Html.BeginForm("ProductTable", "Home", FormMethod.Post, new { @class = "form-horizontal", enctype = "multipart/form-data" }))
{
<div class="row">
<div class="form-horizontal">
<div class="form-group">
<div class="col-md-12">
<label class="col-sm-2 control-label">Hesap kodu</label>
<div class="col-sm-10">
@Html.TextBoxFor(m => m.HesapKodu, new { @class = "form-control" })
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label class="col-sm-2 control-label">Hesap adı</label>
<div class="col-sm-10">
@Html.TextAreaFor(m => m.HesapAdi, new { @class = "form-control" })
</div>
</div>
</div>
</div>
</div>
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<div class="btn-toolbar pull-right">
<input type="submit" value="save" class="btn btn-primary" />
</div>
</div>
</div>
</div>
}
when i am running this solution i have this error : The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[WebApplication7.Models.HesapTemel]', but this dictionary requires a model item of type 'WebApplication7.Models.HesapTemel'.