简体   繁体   中英

How do I add ONLY specific DB Entity Sets to the ViewData in ASP.NET MVC 4 Entity Framework?

I am attempting to populate my ViewData with ONLY specific DB Entity Sets in my ASP.NET MVC 4 project. Below is what I have so far, but how do I write this "if" statment to accomplish this?

 public PartialViewResult _GetforSelectedStatus(string TargetName)
 {
      _selectedJobDB = new IntegrationDBEntities();
      foreach (Job j in _selectedJobDB.Jobs)
      {
           if (j.Request.TargetName == TargetName)
           {
                //I need to add the Job that meets the above "if" requirment to the ViewData here....
           }
      }
 }

Normally I have been then sending the ViewData Model to the partial view as below, but I don't think this will work since I am not wanting to send the whole model:

 ViewData.Model = _selectedJobDb.Jobs.ToList();
 return PartialView();

How do I add ONLY specific DB Entity Sets to the ViewData and send this to the PartialView?

ViewData.Model = _selectedJobDb.Jobs.Where(j => j.Request.TargetName == TargetName).ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM