1

I am making a web app which make use of multiple tabs. I want show a Data of one type in one tab e.g Student Profile in one tab And in other Tab a different model is needed e.g i need the Registeration model class in the same view

  • Possible duplicate of [How do you handle multiple submit buttons in ASP.NET MVC Framework?](http://stackoverflow.com/questions/442704/how-do-you-handle-multiple-submit-buttons-in-asp-net-mvc-framework) – Minhaj Hussain Jan 16 '17 at 17:12

3 Answers3

3

Yes you can by using either System.Tuple class (or) by means of using a ViewModel (a custom class)

ViewModel Option

public class ViewModel1
{
  public StudentProfile profile {get; set;}
  public Registration Reg {get; set;}
}

Pass this ViewModel1 as your model object to the view (or) bind your view with this model object. It's better than using a Tuple<T1, T2>

Rahul
  • 76,197
  • 13
  • 71
  • 125
0

Yes, you could just add a main view model then nest the tab models within the main view model

public class YourMainViewModel
{
    public Tab1ViewModel Tab1 {get; set;}
    public Tab2ViewModel Tab2 {get; set;}
}

Then in your view, just pass the tab models to your partials (if you are using partials for your tabs)

@{Html.RenderPartial("Tab1", Model.Tab1);}
@{Html.RenderPartial("Tab2", Model.Tab2);}
Bobby Caldwell
  • 150
  • 2
  • 3
0

Yes, I know at least 3 ways to set some models in a single view, but i think the best practice it's to use ViewModels. If you are using entity framework you can do something like that.

Set in Models a class which will be you ViewModel.

public class StudensP_Registration
{
    public IEnumerable<StudentsProfile> studentsp { get;  set; }
    public IEnumerable<Registration> registration { get; set; }

}

Then you call it in your controller like this.

public ActionResult Index()
    {

        StudensP_Registration oc = new StudensP_Registration();
        oc.studentsp = db.StudentsProfile;
        oc.registration = db.Registration;
        return View(oc);
    }

And then in the view

@using Proyect_name_space.Models;
@model StudensP_Registration
   @foreach (ordenes_compra item in Model.studentsp) {#something you      want..}

I hope i can help you.

MisaelGaray
  • 75
  • 2
  • 10
  • Of course, if you have multiple tabs in a single view, add your tab structure and in each tab add a table for example where you can use a foreachstatement for the model you want to set in that tab – MisaelGaray Jul 09 '16 at 18:15