I am doing project about restaurant automation system and this table about products of restaurant. I am using mvc5 and mssql.
Here is table on my Index View:
@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 and urun model:
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; }
}
Controller:
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);
}
}
I was adding product(urun) with modal so used renderaction for modal body.
Here my question:
How do I dynamically edit-delete the rows of the table in "View" and update it to the database with a save button?
or
Should I do this with json ? I mean get all tables data one var and update to database to normally ?
I think you want update, delete rows in a table..Just follow the link below.That will resolve your problem. [ https://www.aspsnippets.com/Articles/MVC-jQuery-CRUD-Select-Insert-Edit-Update-and-Delete-using-jQuery-AJAX-and-JSON-in-ASPNet-MVC.aspx][1]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.