Link to home
Start Free TrialLog in
Avatar of mainrotor
mainrotor

asked on

I need help displaying 2 models in one view in my MVC.Net application with C# code behind

Hi Experts,
I have 2 Models that I want to display in a single view in my MVC.Net application.  
I have a Quote control and an index view for my Quote control.  In the view I want to display both my QuoteHeader and QuoteDetail model.  How can I do this?

Here is my code:

CONTROLLER

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ISDQGenerator.Controllers
{
    public class QuoteController : Controller
    {
        // GET: Quote
        public ActionResult Index()
        {
            return View();
        }
    }
}

Open in new window



VIEW
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@{
    ViewBag.Title = "Quote";
}
<h2>ISD Quote Generator</h2>

<p>Hello, this is our Quote Generating Page!</p>

Open in new window



MODELS

QuoteHeader Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ISDQGenerator.Models
{
    public class QuoteHeader
    {
       public int QuoteHeaderID { get; set; }
       public int CustomerID { get; set; }
       public DateTime  CreatedDate { get; set; }
       public DateTime ExpirationDate { get; set; }
       public String CreatedBy { get; set; }
       public String Notes { get; set; }
    }
}

Open in new window



QuoteDetail Model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ISDQGenerator.Models
{
    public class QuoteDetail
    {
        public int QuoteDetailID { get; set; }
        public int QuoteHeaderID { get; set; }
        public int ItemQty { get; set; }
        public String ItemDescription { get; set; }
        public double ItemPrice { get; set; }
        public double ItemTotal { get; set; }
        public String Notes { get; set; }
    }
}

Open in new window



I don't know if the following is needed, but below is my DBContext code:
using System.Data.Entity;


namespace ISDQGenerator.Models
{
    public class QGeneratorDBContext:DbContext 
    {
        public DbSet<Art>Arts { get; set; }
        public DbSet<Customer> Customers { get; set; }
        public DbSet<Garment> Garments { get; set; }
        public DbSet<QuoteDetail> QuoteDetails { get; set; }
        public DbSet<QuoteHeader> QuoteHeader { get; set; }
        public DbSet<Screen> Screens { get; set; }
        public DbSet<Vendor> Vendors { get; set; }
    }
}

Open in new window


Thank you in advance for your help,
mrotor
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Please create a composite class model:
public class Quote
{
    public QuoteHeader Header { get; set; }
    public QuoteDetail Detail { get; set; }
}

Open in new window

Avatar of mainrotor
mainrotor

ASKER

Miguel,
What should I do after I create the composite class model?
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Okay thank you.  I will give it a try.