473,320 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Accessing items in multiple models in a single view in MVC4

I am having an issue on how to access variables from different views in mvc. They way I have it set up is I have a modal on a view that I would like to display values from multiple models. I know I have to use a foreach statement to iterate through the items, but I do not know how to access the other ones.

This is how I call the model in the view:

Expand|Select|Wrap|Line Numbers
  1. @model IEnumerable<MyApp.Models.Problems>
Here is my model where I am trying to access the values:
Expand|Select|Wrap|Line Numbers
  1. public class Problems
  2.     {
  3.         public int Id { get; set; }
  4.         public string Title { get; set; }
  5.  
  6.         public IEnumerable<MyApp.Models.Category> Categories { get; set; }
  7.         public IEnumerable<MyApp.Models.Type> Types {get; set;}
  8.  
  9.     }
This is my other models:
Expand|Select|Wrap|Line Numbers
  1. public partial class Category
  2.     {
  3.         public int Id { get; set; }
  4.         public string Title { get; set; }
  5.     }
  6.  
  7. public partial class Type
  8.     {
  9.         public int Id { get; set; }
  10.         public int Order { get; set; }
  11.         public string Description { get; set; }
  12.     }
Here is an example of what I am trying to do:

This calls the Title in my Problems model which is being loaded:
Expand|Select|Wrap|Line Numbers
  1. @Html.DisplayNameFor(model => model.Title)
But I want it to be able to call the Category Title in the same view. Anybody have any idea or can point me in the right direction it would be greatly appreciated!!!
Apr 24 '14 #1
1 1404
Frinavale
9,735 Expert Mod 8TB
You can create a view for the IEnumerable of your Type model and another view for the IEnumerable of your Category model.

Then you can use @Html.DisplayFor(model => model.Categories) and @Html.DisplayFor(model => model.Types)

-Frinny
May 7 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: d.schulz81 | last post by:
Hi all how can i manipulate a multiple select into a single select dropdown field with JavaScript? thanks
1
by: AP | last post by:
Is there a way to change a subform from single view to continuous view without switching back to design view. I have used the run command in the past to switch to datasheet view, but cant seem to...
1
by: sherif | last post by:
when i access the items in a combobox by using the value member property i find that the retreived values aren't correct so could you tell me how to access them right.
0
by: rayone | last post by:
Hi folks. I need advice. 2 options, which do you think is the better option to display/retrieve/report on the data. Keep in mind reporting (Crystal), SQL Performance, VB Code, usability,...
6
by: Tark Siala | last post by:
hi where i can find single view of any Sub or Function in VS.Net 2003 (like vb6)? -- Best Regards Tark M. Siala
7
by: jason.langdale | last post by:
I have 3 tables I want to use in a view. Table A has field 1,2,3,4,5 and table B has field 1,2,3,4,5. I want to do a union on these. (I have done so successfully if I stop here) I also want to join...
1
by: prpradip | last post by:
In my application ListView is inside panel (XP theme enable), item text in the ListView control overlaps other items in small icon view. The items are drawn as if aligned to a grid and this causes...
5
Frinavale
by: Frinavale | last post by:
I'm playing with an ASP.NET MVC application and I've run into a bit of a problem. I am pretty new to ASP.NET MVC and just barely understand the basics to get things to work at this point. I have a...
5
by: MandarkDC | last post by:
I am a total novice at access, who wants to move his inventory from Excel to Access, and add some functionality. One question that I haven't really seen answered in the general introductions to...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.