Click here to Skip to main content
15,894,540 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This might be difficult to explain but please bear with me... So, I have a model that combines two different models so that I can utilize data found in both in one view: Combined:

C#
public class EventFullModel
{
    public AccessListModel AccessPointsList;
    public EventListModel EventList;
}


Access List Model:
C#
public class AccessListModel
{
    public int Id { get; set; }
    public List<SelectListItem> AccessPoints { get; set; }
}


Event List Model:
C#
public class EventListModel
{
    public int Id { get; set; }
    public virtual string T { get; set; }
    public virtual string C { get; set; }
    public virtual string M { get; set; }
    public virtual string L { get; set; }
    public List<SelectListItem> Events { get; set; }
    public IEnumerable<SelectListItem> Skills { get; set; }
}


I am currently getting an error which I believe stems from the fact that the controller method for this view originally returned just the EventListModel whereas now it is trying to return the EventFullModel since I changed the inheritance: Inherits="System.Web.Mvc.ViewPage<cred.web.models.eventfullmodel>". So at this point I am trying to edit the controller to make sure it attempts to return the correct model for the view. My problem is the following:

This is a GET action method that only accepts (int? id) as a parameter.
Originally, the controller worked only with the EventListModel:
C#
EventListModel model;
model = new EventListModel {
Id = 0,
T = "",
C = "",
M = "",
L = HttpContext.Session["L"].IsNull() ? "" : HttpContext.Session["L"].ToString(),
Events = new List<SelectListItem>(),
Skills =
        DbQueryExecutor.ExecuteQuery(new SkillsList()).Select(e => new SelectListItem { Text = e.Certification, Value = e.Certification, Selected = false })


So I am basically wondering, how can I edit this to access those pieces of the EventListModel but have my model = new EventFullModel?

(Disclaimer: I have altered the names of a few things and I am working to edit a piece of software that I did not originally write so I am trying to change as little as possible in the hopes of not "breaking" other pieces of the software)
Posted
Updated 14-May-13 2:47am
v2

It seems that you have problem in accessing multiple models.
The Model binding to the page should still be EventFullModel and you can access EventListModel as property of the EvenFullModel.
This may Help you : Sample
 
Share this answer
 
Comments
jfabus09 14-May-13 8:47am    
The sample you have provided looks to be using a different method of accessing two models in one view and/or controller and that doesn't look to be the route that I was looking to take. I guess I'll try and implement something like that but I was hoping you might try to give me an example of what you meant? This is a GET action method by the way.
The solution ended up looking like this:

C#
EventListModel modelEvent;
AccessListModel modelAccess;

modelEvent = new EventListModel {
  Id = 0,
  ...}
modelAccess = new AccessListModel {
  Id = 0,
  ...}

var modelFull = new EventFullModel {
  EventsList = modelEvent,
  AccessPointsList = modelAccess };

return View(modelFull);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900