Skip to content
Loading
  • Ramesh Palanivel
    0
    Hi Sanjeev kumar, 
     
    You can achieve this in different ways,
     
    1. Nesting of Complex objects - Example
     
    1. public class student  
    2. {  
    3. public int studentid{get;set;}  
    4. public string studentname{get;set;}   
    5. }   
    6.    
    7. public class teacher  
    8. {  
    9. public int teacherid{get;set;}  
    10. public string teachername{get;set;}   
    11. }   
    12.   
    13.    
    14. public class school  
    15. {  
    16. public student _student{get;set;}  
    17. public teacher _teacher{get;set;}   
    18. }   
     
    You can send the school model to your view and from school model you can get student and teacher model
     
    2.  Using Tuple you can pass multiple model. Please find the sample controller code
     
    1. Model  
    2. ===================  
    3. public class student  
    4. {  
    5. public int studentid{get;set;}  
    6. public string studentname{get;set;}   
    7. }   
    8.    
    9. public class teacher  
    10. {  
    11. public int teacherid{get;set;}  
    12. public string teachername{get;set;}   
    13. }   
    14.   
    15.    
    16. public class school  
    17. {  
    18. public student _student{get;set;}  
    19. public teacher _teacher{get;set;}   
    20. }   
    21.   
    22. Controller  
    23. ==================  
    24.   
    25. public ActionResult GetSchoolDetails()  
    26. {  
    27. Student _student=//Get student info using your db context;  
    28. Teacher _teacher=//Get teacher info using your db context;  
    29. Tuple _schoolModel=new Tuple(_student,_teacher);  
    30. return View(_schoolModel);  
    31. }  
    32.   
    33. View  
    34. ==================  
    35. @Model Tuple  
    36.   
    37. To access student info,  
    38.   
    39. @Model.Item1.studentid,@Model.Item1.studentname  
    40.   
    41. To access teacher info  
    42.   
    43. @Model.item2.teacherid,@model.item2.teachername  
    3. Using View bag send the multiple models, But this is for rare case. using more viewbag is not good coding standards.
     
    1. Controller    
    2. ==================    
    3.     
    4. public ActionResult GetSchoolDetails()    
    5. {    
    6. Viewbag._student=//Get student info using your db context;    
    7. Viewbag._teacher=//Get teacher info using your db context;     
    8. return View();    
    9. }    
    10.     
    0
  • 0
    all model in master model.when how can do.
    0
  • Ramesh Palanivel
    0
    Hi Sanjeev,
     
    Please share some sample code your model and view. 
    0