Click here to Skip to main content
15,886,919 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionEncrypting Database Credentials Pin
indian14322-Aug-12 15:20
indian14322-Aug-12 15:20 
AnswerRe: Encrypting Database Credentials Pin
Paul Conrad22-Aug-12 16:08
professionalPaul Conrad22-Aug-12 16:08 
AnswerRe: Encrypting Database Credentials Pin
Niladri_Biswas22-Aug-12 18:48
Niladri_Biswas22-Aug-12 18:48 
QuestionAsp.Net - Oracle Connection failed Pin
lalithafranklyn22-Aug-12 9:46
lalithafranklyn22-Aug-12 9:46 
AnswerRe: Asp.Net - Oracle Connection failed Pin
Niladri_Biswas22-Aug-12 18:29
Niladri_Biswas22-Aug-12 18:29 
QuestionFTP virtual path .net 2.0 Pin
lalithafranklyn22-Aug-12 9:31
lalithafranklyn22-Aug-12 9:31 
AnswerRe: FTP virtual path .net 2.0 Pin
Sandip.Nascar22-Aug-12 11:12
Sandip.Nascar22-Aug-12 11:12 
Questionasp.net mvc 3.0 -> showing description instead of ID in a toList() call Pin
Marcel Vreuls (www.agentbase.nl)21-Aug-12 14:09
Marcel Vreuls (www.agentbase.nl)21-Aug-12 14:09 
Hi All,

I am fairly new to the MVC and am strugling with comboboxes/dropdown lists all day, but have the better part working. The following is my problem.

I have 2 models defined
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace AgentBase.ContentRepository.Models
{
    public class cContent
    {

        public int ID { get; set; }
        public string CO_TITLE { get; set; }
        public string CO_TAGS { get; set; }
        public string CO_SUMMARY { get; set; }
        public bool CO_INTEXT { get; set; }
        public Int32 CO_TYPE { get; set; } //
        public decimal CO_SIZE { get; set; }
        public string CO_NOTES { get; set; }
        public string CO_COPYRIGHT { get; set; }
    }

}


and

C#
using System;
using System.Data.Entity;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AgentBase.ContentRepository.Models
{
    public class cCategory
    {
        public int ID { get; set; }
        public string CA_DESCRIPTION { get; set; }
        public Int32 CA_PARENT { get; set; }
        public bool CA_ACTIVE { get; set; }
        
    }

}


Then i have 2 controllers defined

C#
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AgentBase.ContentRepository.Models;

namespace AgentBase.ContentRepository.Controllers
{ 
    public class ContentRecordsController : Controller
    {
        private ContentRepositoryObjects db = new ContentRepositoryObjects();
        

        //
        // GET: /ContentRecords/
       

        public ViewResult Index()
        {
            //
            //------------------------------------------------------------------------
            var query = db.Categories.Select(c => new { c.ID, c.CA_DESCRIPTION });
            ViewBag.Categories = new SelectList(query.AsEnumerable(), "ID", "CA_DESCRIPTION");
           
            return View(db.ContentRecords.ToList());
            
        }

        //
        // GET: /ContentRecords/Details/5

        public ViewResult Details(int id)
        {
            cContent ccontent = db.ContentRecords.Find(id);
            //------------------------------------------------------------------------
            var query = db.Categories.Select(c => new { c.ID, c.CA_DESCRIPTION });
            ViewBag.Categories = new SelectList(query.AsEnumerable(), "ID", "CA_DESCRIPTION");
            return View(ccontent);
        }

        //
        // GET: /ContentRecords/Create

        public ActionResult Create()
        {
            //------------------------------------------------------------------------
            //var db = new NorthwindDataContext();           
            //------------------------------------------------------------------------
            var query = db.Categories.Select(c => new { c.ID, c.CA_DESCRIPTION });
            ViewBag.Categories = new SelectList(query.AsEnumerable(),"ID", "CA_DESCRIPTION");
            //------------------------------------------------------------------------
            return View();
        } 

        //
        // POST: /ContentRecords/Create

        [HttpPost]
        public ActionResult Create(cContent ccontent)
        {
            if (ModelState.IsValid)
            {
                db.ContentRecords.Add(ccontent);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(ccontent);
        }
        
        //
        // GET: /ContentRecords/Edit/5
 
        public ActionResult Edit(int id)
        {
            cContent ccontent = db.ContentRecords.Find(id);
            //Fill the Dropdown.
            //------------------------------------------------------------------------
            var query = db.Categories.Select(c => new { c.ID, c.CA_DESCRIPTION });
            ViewBag.Categories = new SelectList(query.AsEnumerable(), "ID", "CA_DESCRIPTION");
            //------------------------------------------------------------------------

            return View(ccontent);
        }

        //
        // POST: /ContentRecords/Edit/5

        [HttpPost]
        public ActionResult Edit(cContent ccontent)
        {
            if (ModelState.IsValid)
            {
                db.Entry(ccontent).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(ccontent);
        }

        //
        // GET: /ContentRecords/Delete/5
 
        public ActionResult Delete(int id)
        {
            cContent ccontent = db.ContentRecords.Find(id);
            return View(ccontent);
        }

        //
        // POST: /ContentRecords/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            cContent ccontent = db.ContentRecords.Find(id);
            db.ContentRecords.Remove(ccontent);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}


and
C#
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AgentBase.ContentRepository.Models;

namespace AgentBase.ContentRepository.Controllers
{ 
    public class CategoryController : Controller
    {
        private ContentRepositoryObjects db = new ContentRepositoryObjects();

        //
        // GET: /Category/

        public ViewResult Index()
        {
            return View(db.Categories.ToList());
        }

        //
        // GET: /Category/Details/5

        public ViewResult Details(int id)
        {
            cCategory ccategory = db.Categories.Find(id);
            return View(ccategory);
        }

        //
        // GET: /Category/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Category/Create

        [HttpPost]
        public ActionResult Create(cCategory ccategory)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(ccategory);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(ccategory);
        }
        
        //
        // GET: /Category/Edit/5
 
        public ActionResult Edit(int id)
        {
            cCategory ccategory = db.Categories.Find(id);
            return View(ccategory);
        }

        //
        // POST: /Category/Edit/5

        [HttpPost]
        public ActionResult Edit(cCategory ccategory)
        {
            if (ModelState.IsValid)
            {
                db.Entry(ccategory).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(ccategory);
        }

        //
        // GET: /Category/Delete/5
 
        public ActionResult Delete(int id)
        {
            cCategory ccategory = db.Categories.Find(id);
            return View(ccategory);
        }

        //
        // POST: /Category/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            cCategory ccategory = db.Categories.Find(id);
            db.Categories.Remove(ccategory);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}


then problem now is. That i have a list page where i call

C#
public ViewResult Index()
       {
           //
           //------------------------------------------------------------------------
           var query = db.Categories.Select(c => new { c.ID, c.CA_DESCRIPTION });
           ViewBag.Categories = new SelectList(query.AsEnumerable(), "ID","CA_DESCRIPTION");

           return View(db.ContentRecords.ToList());

       }


The index page shows me then all records from the ContentRecords.ToList function but that is showing me the CO_TYPE field ID, instead of the corresponding CA_DESCRIPTION from the categories entity. Because CO_TYPE is related to the CA_ID.

So how can I make it possible that the toList function:
a) returns values from two linked entities/models.
or
b) how can i create a new model based on two other more other models by joining them.
or
c) any other method i did not think of Wink | ;-)

I hope i have made a clear point of my problem. I am stuck any help will be appreciated.
Kind regards,

Marcel Vreuls

AgentBase

<<A good idea can change your life>>

QuestionUpdating or inserting entities using Entity Framework Pin
indian14321-Aug-12 6:07
indian14321-Aug-12 6:07 
AnswerRe: Updating or inserting entities using Entity Framework Pin
Niladri_Biswas22-Aug-12 18:50
Niladri_Biswas22-Aug-12 18:50 
QuestionHow to capture webcam videos using C# and ASP.NET Pin
vinay_sinha20-Aug-12 23:30
vinay_sinha20-Aug-12 23:30 
QuestionPage.ResolveUrl and reverse proxy Pin
Sebastiaan Meijerink20-Aug-12 22:21
professionalSebastiaan Meijerink20-Aug-12 22:21 
Questionexecute a certain task every one hour in server Pin
Farhad Eft20-Aug-12 13:01
Farhad Eft20-Aug-12 13:01 
AnswerRe: execute a certain task every one hour in server Pin
fjdiewornncalwe20-Aug-12 16:08
professionalfjdiewornncalwe20-Aug-12 16:08 
GeneralRe: execute a certain task every one hour in server Pin
Farhad Eft20-Aug-12 22:08
Farhad Eft20-Aug-12 22:08 
AnswerRe: execute a certain task every one hour in server Pin
Rahul Rajat Singh20-Aug-12 17:55
professionalRahul Rajat Singh20-Aug-12 17:55 
GeneralRe: execute a certain task every one hour in server Pin
Farhad Eft20-Aug-12 22:08
Farhad Eft20-Aug-12 22:08 
AnswerRe: execute a certain task every one hour in server Pin
Rahul Rajat Singh20-Aug-12 22:27
professionalRahul Rajat Singh20-Aug-12 22:27 
SuggestionRe: execute a certain task every one hour in server Pin
Karthik J, Coimbatore20-Aug-12 23:25
Karthik J, Coimbatore20-Aug-12 23:25 
AnswerRe: execute a certain task every one hour in server Pin
David Mujica21-Aug-12 2:03
David Mujica21-Aug-12 2:03 
AnswerRe: execute a certain task every one hour in server Pin
Sandip.Nascar22-Aug-12 10:57
Sandip.Nascar22-Aug-12 10:57 
AnswerRe: execute a certain task every one hour in server Pin
Vijay Selvaraj27-Aug-12 0:13
Vijay Selvaraj27-Aug-12 0:13 
Questionconfigure IIS 7 to run with current user account Pin
indian14320-Aug-12 10:38
indian14320-Aug-12 10:38 
Questionimage control from Image Pin
Jassim Rahma20-Aug-12 8:56
Jassim Rahma20-Aug-12 8:56 
AnswerRe: image control from Image Pin
Wes Aday20-Aug-12 9:21
professionalWes Aday20-Aug-12 9:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.