Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:17:41+00:00 2026-06-15T19:17:41+00:00

I have created a ViewModel called DashboardViewModel: public class DashboardViewModel { public Hardware Hardware

  • 0

I have created a ViewModel called DashboardViewModel:

public class DashboardViewModel
{        
    public Hardware Hardware { get; set; }
    public Software Software { get; set; }      
}

I am passing the ViewModel to the view in my ActionResult. But I need to pass other things too. Here is my ActionResult:

public ActionResult Index()
{

    HardwareType hwt = new HardwareType { HType = "PC" };
    IEnumerable<Hardware> Pcs = db.Hardware.Where(h => h.HardwareType.Contains(hwt));

    DashboardViewModel dvm = new DashboardViewModel();   

    return View(dvm);
}

How do I pass Pcs to the view if I am already passing dvm? I don’t even know if this is the right approach. What I am trying to accomplish is to create navigation on the page. So not only will I have PCs, but I’ll have monitors and printers to pass to the view, as well as software. Here is my hardware class:

public class Hardware
{
    public int Id { get; set; }
    public virtual ICollection<DeviceType> Type { get; set; }
    public string AssetTagId { get; set; }
    public virtual ICollection<Manufacturer> Manufacturer { get; set; }
    [Required]
    [StringLength(50)]
    public string ServiceTagId { get; set; }
    [Required]
    [StringLength(50)]
    public string SerialNumber { get; set; }
    [Required]
    [StringLength(75)]
    public string ProductNumber { get; set; }
    // [Required]
    [StringLength(20)]
    public string PurchaseDate { get; set; }
    [StringLength(20)]
    public string WarrantyExpiration { get; set; }
    [Required]
    [StringLength(20)]
    public string WarrantyType { get; set; }
    public virtual ICollection<Location> Location { get; set; }
    public virtual ICollection<HardwareType> HardwareType { get; set; }
    [Required]
    [StringLength(2000)]
    public string Notes { get; set; }
    public string POATag { get; set; }
}

What is the best approach for what I want to do (creating the navigation with various categories of hardware and software)? I’m new to MVC and am trying to follow suggestions on what to do, but I could use a higher level approach as maybe I’m going about this all wrong. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:17:43+00:00Added an answer on June 15, 2026 at 7:17 pm

    You can put your Pcs in ViewBag or ViewData as below:

    public ActionResult Index()
    {
    
        HardwareType hwt = new HardwareType { HType = "PC" };
        IEnumerable<Hardware> Pcs = db.Hardware.Where(h => h.HardwareType.Contains(hwt));
        ViewBag.Pcs=Pcs;//or ViewData["Pcs"]=Pcs;
    
        DashboardViewModel dvm = new DashboardViewModel();   
    
        return View(dvm);
    }
    

    ViewBag is the dynamic object. You can add anything to it. With any name e.g. yous Pcs can also be stored in ViewBag as ViewBag.AnyNameYouLike=Pcs;

    **RAZOR SYNTAX:**
    

    Just apply loop and you are done.

    @foreach(var pc in ViewBag.Pcs)
    {
      @pc.Id;//Will give you id
    
    }
    

    You can loop through all properties like this

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have created the folloiwng view model class public class viewmodelclass { public IEnumerable<Question>
I have a button created in my view. In the ViewModel, I wish to
I have two classes called Company and Address . I have created a ViewModel
In my ASP.NET MVC2 application, I have a ViewModel class called UserCreateViewModel. In this
I have created my own custom ValidationAttribute : public class UrlValidationAttribute : ValidationAttribute {
if i have created a view model and have a partial form that is
I have created a custom ItemsControl called Toolbox. I want to be able to
I have a ViewModel called MainWindowViewModel. In this I have a property that shows
I have two viewmodel classes called ChangePwdViewModel.cs and ExpiringPwdViewModel.cs . ChangPwd.xaml binds to ChangePwdViewModel
I have a ViewModel class that implements the IDataErrorInfo Interface . In each property's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.