Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi, i am just new to umbraco please any one can help me. how can i perform Insert ,update and delete operation in umbraco using surfacecontroller.
They are all exposed as services: Application.Services.ContentService Application.Services.xxx
https://our.umbraco.org/documentation/reference/management/services/contentservice
Hi Amit,
Do you mean CRUD operations on content or on a custom database ?
For content you can use the content service : https://our.umbraco.org/documentation/reference/management/services/contentservice
If it's a database CRUD you can use thisblogposts a a starting point : https://creativewebspecialist.co.uk/2013/07/16/umbraco-petapoco-to-store-blog-comments/
Dave
Import -> Umbraco.Web.Mvc or use Umbraco.Web.Mvc.SurfaceController
private DemoDbEntities db = new DemoDbEntities(); // GET: Products public ActionResult Index() { return View(db.Products.ToList()); } // GET: Products/Details/5 public ActionResult Details(Guid? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Product product = db.Products.Find(id); if (product == null) { return HttpNotFound(); } return View(product); } // GET: Products/Create public ActionResult Create() { return View(); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create([Bind(Include = "ProductID,Name,Price")] Product product) { if (ModelState.IsValid) { product.ProductID = Guid.NewGuid(); db.Products.Add(product); db.SaveChanges(); return Redirect("~/Umbraco/Surface/Products/Index"); //return RedirectToAction("Index"); } return View(product); } // GET: Products/Edit/5 public ActionResult Edit(Guid? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Product product = db.Products.Find(id); if (product == null) { return HttpNotFound(); } return View(product); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include = "ProductID,Name,Price")] Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return Redirect("~/Umbraco/Surface/Products/Index"); //return RedirectToAction("Index"); } return View(product); } // GET: Products/Delete/5 public ActionResult Delete(Guid? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Product product = db.Products.Find(id); if (product == null) { return HttpNotFound(); } return View(product); } // POST: Products/Delete/5 [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public ActionResult DeleteConfirmed(Guid id) { Product product = db.Products.Find(id); db.Products.Remove(product); db.SaveChanges(); return Redirect("~/Umbraco/Surface/Products/Index"); //return RedirectToAction("Index"); } protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); } }
}
Hope it helps.
Hi
Would you be able to show what the view would look like please. I’m especially interested in how you call each action from the front end. Thanks
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
CRUD operation in umbraco using surface controller
Hi, i am just new to umbraco please any one can help me. how can i perform Insert ,update and delete operation in umbraco using surfacecontroller.
They are all exposed as services: Application.Services.ContentService Application.Services.xxx
https://our.umbraco.org/documentation/reference/management/services/contentservice
Hi Amit,
Do you mean CRUD operations on content or on a custom database ?
For content you can use the content service : https://our.umbraco.org/documentation/reference/management/services/contentservice
If it's a database CRUD you can use thisblogposts a a starting point : https://creativewebspecialist.co.uk/2013/07/16/umbraco-petapoco-to-store-blog-comments/
Dave
Import -> Umbraco.Web.Mvc or use Umbraco.Web.Mvc.SurfaceController
}
Hope it helps.
Hi
Would you be able to show what the view would look like please. I’m especially interested in how you call each action from the front end. Thanks
is working on a reply...