我正在做有关餐厅自动化系统的项目以及关于餐厅产品的这张表。我正在使用mvc5和mssql。
这是我的索引视图中的表格:
@model Starset.Models.ViewModel.MixModel2
<table class="table table-hover mb-0">
<thead>
<tr>
<th>Ad</th>
<th>Fiyat</th>
<th>KDV</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item2 in Model.urunobj)
{
<tr>
<td>@Html.DisplayFor(modelItem => item2.urun_ad)</td>
<td>@Html.DisplayFor(modelItem => item2.urun_fiyat)</td>
<td>@Html.DisplayFor(modelItem => item2.urun_kdv)</td>
<td></td>
<td class="td-actions">
<a href="#"><i class="la la-edit edit"></i></a>
<a href="#"><i class="la la-close delete"></i></a>
</td>
</tr>
}
</tbody>
</table>
MixModel2和urun模型:
public class MixModel2
{
public IEnumerable<kategori> katobj { get; set; }
public IEnumerable<urun> urunobj { get; set; }
public siparis sipobj { get; set; }
}
public partial class urun
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public urun()
{
this.siparis = new HashSet<siparis>();
}
public int urun_id { get; set; }
public Nullable<int> kategori_id { get; set; }
public string urun_ad { get; set; }
public string urun_fiyat { get; set; }
public string urun_kdv { get; set; }
public virtual kategori kategori { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<siparis> siparis { get; set; }
}
控制器:
public class UrunController : Controller
{
private tdgEntitiess db = new tdgEntitiess();
// GET: Urun
public ActionResult Index()
{
var mixmodel2 = new MixModel2
{
katobj = db.kategori.Include(p => p.urun).ToList(),
urunobj = db.urun.Include(a => a.kategori).ToList(),
};
ViewBag.tab = "tab";
return View(mixmodel2);
}
}
我正在添加带有模态的product(urun),所以对模态主体使用了renderaction。
这是我的问题:
如何动态编辑-删除“视图”中表的行并使用保存按钮将其更新到数据库?
或
我应该用json吗?我的意思是让所有表数据都变一个var并正常更新到数据库?
答案 0 :(得分:0)