473,406 Members | 2,208 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,406 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 1408
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.