Click here to Skip to main content
15,176,561 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Team

I am struggling to bind many models in one single view. Let me share what i have below

What I have tried:

// Model one
public class ApplicationName
 {
     public int PNR { get; set; }

     public string FIS { get; set; }
     public string Telegrams { get; set; }

     public string Transaction_Code { get; set; }

     public string TS_Logs { get; set; }

     public string Readers_Logs { get; set; }

     public List<TrackingDropDown> TrackingName { get; set; }

 }


// Model two
C#
public class SystemApplication
  {
      public int SystemID { get; set; }
      public string Optimo { get; set; }

      public string RACS { get; set; }


      public string Stacker_Cranes { get; set; }


      public string BIW_Services { get; set; }

      public string IP_Services { get; set; }


      public string KP_Services { get; set; }

      public List<NameDropDown> NameDrops { get; set; }

  }


// One single View
HTML
@using CheckTimeLine.Models
@model CheckTimeLine.Models.ApplicationName

@{
    ViewBag.Title = "Home Page";
}
Posted
Updated 6-Nov-21 1:50am
v2
Comments
Gerry Schmitz 2-Nov-21 14:03pm
   
You add a reference (getter) in one to the other; in whichever one you want to be your "main model" / parent model. Then qualify those "child" properties with the name of the reference / getter when binding.
#realJSOP 4-Nov-21 16:30pm
   
Are you in the same programming class as "mrnewguy"?

1 solution

I posted an article yesterday about this very topic.

Multiple Models In a MVC View[^]
   

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