Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • daniel 7 posts 37 karma points
    Jul 21, 2014 @ 16:16
    daniel
    0

    Surface Control connect to database external

    Hi good morning, I wonder if some could guide me on how to solve a problem. I have a site in umbraco 7.1.4 and have the need to connect to an external database not to umbraco, and display data from that database datos.He tried to do this using a control surface and entity framwork but I could not access the path or url controller surface. I would like to give a guide to how I could resolve this issue.

    Thank you very much.

    My Control surface

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Entity;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using SurfacceConBD.Models;
    
    
    namespace SurfacceConBD.Controllers
    {
    public class PersonasSurfaceController : Umbraco.Web.Mvc.SurfaceController
    {
        private DataModelPersonasEntities db = new DataModelPersonasEntities();
    
        //
        // GET: /Personas/    
    
        public ActionResult Index()
        {
            return View(db.personas.ToList());
        }
    
        //
        // GET: /Personas/Details/5
    
        public ActionResult Details(string id = null)
        {
            personas personas = db.personas.Find(id);
            if (personas == null)
            {
                return HttpNotFound();
            }
            return View(personas);
        }
    
        //
        // GET: /Personas/Create
    
        public ActionResult Create()
        {
            return View();
        }
    
        //
        // POST: /Personas/Create
    
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(personas personas)
        {
            if (ModelState.IsValid)
            {
                db.personas.Add(personas);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
    
            return View(personas);
        }
    
        //
        // GET: /Personas/Edit/5
    
        public ActionResult Edit(string id = null)
        {
            personas personas = db.personas.Find(id);
            if (personas == null)
            {
                return HttpNotFound();
            }
            return View(personas);
        }
    
        //
        // POST: /Personas/Edit/5
    
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(personas personas)
        {
            if (ModelState.IsValid)
            {
                db.Entry(personas).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(personas);
        }
    
        //
        // GET: /Personas/Delete/5
    
        public ActionResult Delete(string id = null)
        {
            personas personas = db.personas.Find(id);
            if (personas == null)
            {
                return HttpNotFound();
            }
            return View(personas);
        }
    
        //
        // POST: /Personas/Delete/5
    
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(string id)
        {
            personas personas = db.personas.Find(id);
            db.personas.Remove(personas);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
    
        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
      }
    }
    

    My View Index in Folder Personas/Index

     @model IEnumerable<SurfacceConBD.Models.personas>
     @{
       ViewBag.Title = "Index";
     }
    
     <h2>Index</h2>
    
     <p>
        @Html.ActionLink("Create New", "Create")
     </p>
     <table>
       <tr>
        <th>
            @Html.DisplayNameFor(model => model.nombre)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.edad)
        </th>
        <th></th>
    </tr>
    
    @foreach (var item in Model) {
       <tr>
        <td>
            @Html.DisplayFor(modelItem => item.nombre)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.edad)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
            @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */          }) |
            @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
        </td>
      </tr>
     }
    

Please Sign in or register to post replies

Write your reply to:

Draft