我正在制作一个使用多个标签的网络应用。 我希望在一个选项卡中显示一种类型的数据,例如一个选项卡中的学生档案 在其他选项卡中需要一个不同的模型,例如我需要在同一视图中使用Registeration模型类
答案 0 :(得分:3)
是的,您可以使用System.Tuple
类(或)通过使用ViewModel
(自定义类)
ViewModel选项
public class ViewModel1
{
public StudentProfile profile {get; set;}
public Registration Reg {get; set;}
}
将此ViewModel1
作为模型对象传递给视图(或)将视图与此模型对象绑定。它比使用Tuple<T1, T2>
答案 1 :(得分:0)
是的,您可以添加主视图模型,然后将选项卡模型嵌套在主视图模型中
public class YourMainViewModel
{
public Tab1ViewModel Tab1 {get; set;}
public Tab2ViewModel Tab2 {get; set;}
}
然后在您的视图中,只需将标签模型传递给您的部分(如果您使用部分标签)
@{Html.RenderPartial("Tab1", Model.Tab1);}
@{Html.RenderPartial("Tab2", Model.Tab2);}
答案 2 :(得分:0)
是的,我知道至少有3种方法可以在一个视图中设置一些模型,但我认为使用ViewModel是最好的做法。 如果你正在使用实体框架,你可以做类似的事情。
在模型中设置一个将成为ViewModel的类。
public class StudensP_Registration
{
public IEnumerable<StudentsProfile> studentsp { get; set; }
public IEnumerable<Registration> registration { get; set; }
}
然后你就像这样在控制器中调用它。
public ActionResult Index()
{
StudensP_Registration oc = new StudensP_Registration();
oc.studentsp = db.StudentsProfile;
oc.registration = db.Registration;
return View(oc);
}
然后在视图中
@using Proyect_name_space.Models;
@model StudensP_Registration
@foreach (ordenes_compra item in Model.studentsp) {#something you want..}
我希望我能帮助你。