Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function izbrisiAjax(compID) {
- $.ajax({
- url: '@Url.Action("Delete", "Company")',
- method: "POST",
- data: JSON.stringify({id : compID}),
- dataType: "json",
- contentType: "application/json; charset=utf-8",
- success: function (data) {
- $("#" + compID).hide();
- initFeatures();
- }
- });
- initFeatures();
- };
- --------------------------------------------
- indexTable
- @model List<Vjezba.Web.Models.Mock.Company>
- <table id="tbl-companies" class="table table-condensed table-hover">
- <thead>
- <tr>
- <th>#</th>
- <th>Naziv</th>
- <th>Adresa</th>
- <th>Datum osnivanja</th>
- <th>Email</th>
- <th>Grad</th>
- <th>Akcija</th>
- </tr>
- </thead>
- <tbody>
- @foreach (var company in Model)
- {
- <tr id="@company.ID" onmouseover="setMaxOpacity(this);" onmouseout="setLowOpacity(this);">
- <td>@company.ID</td>
- <td>@Html.ActionLink(company.Name, "Details", new { id = company.ID })</td>
- <td>@company.Address</td>
- <td>@company.DateFrom.ToShortDateString()</td>
- <td>@company.Email</td>
- @if (company.City != null)
- {
- <td>@company.City.Name</td>
- }
- else
- {
- <td>Nema grada</td>
- }
- <td>@Html.ActionLink("Uredi", "Edit", new { id = company.ID }) | <a href="#" onclick="izbrisiAjax(@company.ID)">Izbrisi</a></td>
- </tr>
- }
- </tbody>
- </table>
- [HttpPost]
- public JsonResult Delete(int? id=0)
- {
- var dbContext = new CompaniesManagerDbContext();
- if (id == 0)
- return Json("Fail");
- var kompanija = dbContext.Companies.Find(id);
- dbContext.Entry(kompanija).State = System.Data.Entity.EntityState.Deleted;
- dbContext.SaveChanges();
- return Json("Success");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement