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
VIEW
MODELS
QuoteHeader Model
QuoteDetail Model
I don't know if the following is needed, but below is my DBContext code:
Thank you in advance for your help,
mrotor
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();
}
}
}
VIEW
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@{
ViewBag.Title = "Quote";
}
<h2>ISD Quote Generator</h2>
<p>Hello, this is our Quote Generating Page!</p>
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; }
}
}
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; }
}
}
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; }
}
}
Thank you in advance for your help,
mrotor
ASKER
Miguel,
What should I do after I create the composite class model?
What should I do after I create the composite class model?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay thank you. I will give it a try.
Open in new window