Multiple models in a view

前端 未结 12 1828
太阳男子
太阳男子 2020-11-21 23:07

I want to have 2 models in one view. The page contains both LoginViewModel and RegisterViewModel.

e.g.

pub         


        
12条回答
  •  终归单人心
    2020-11-21 23:26

    a simple way to do that

    we can call all model first

    @using project.Models
    

    then send your model with viewbag

    // for list
    ViewBag.Name = db.YourModel.ToList();
    
    // for one
    ViewBag.Name = db.YourModel.Find(id);
    

    and in view

    // for list
    List Name = (List)ViewBag.Name ;
    
    //for one
    YourModel Name = (YourModel)ViewBag.Name ;
    

    then easily use this like Model

提交回复
热议问题