.net向前台传入多个对象
2016-12-05 本文已影响4人
飞天猪Pony
后台:
public ActionResult Index(int? id)
{
//通过id找到该用户
User user = db.User.find(id);
//初始化
DoctorAndUserClass doctoranduserclass = new DoctorAndUserClass();
//将user赋值给类中的User对象
doctoranduserclass.User = user;
//找到所用的doctor
var doctor = db.Doctor.where(j=>1==1);
//将doctor列表赋值给类中的Doctor对象
doctoranduserclass.Doctor = doctor.ToList();
return View(doctoranduserclass);
}
此类创建了两个对象Doctor<Doctor>和User
public class DoctorAndUserClass
{
public Doctor<Doctor> Doctor { get; set;}
public User User { get; set;}
}
前台:
顶部应改为:
@model Tasly.Portal.Controllers.UserCenterController.DoctorAndUserClass
这样就可以使用Doctor和User了
使用方法:Model.Doctor和Model.User.