c# - Return 2 lists from one model to a view in MVC -


i new mvc, , struggling viewmodels. return 2 lists same model 1 view. need 2 foreach loops show records of different "status" on 1 view. because both lists coming 1 model, necessary create viewmodel?

i have tried following, view not finding item type each list.

 public class pipelineviewmodel  {     public int leadid { get; set; }     public string firstname { get; set; }     public string lastname { get; set; }     public string status{ get; set; }     public string loanagent{ get; set; }      public list<weblead> pipenewleads { get; set; }     public list<weblead> pipedispleads { get; set; } } 

note list domain model table pulling lists from. correct?

next in controller:

    public actionresult index(string loanagent)     {         var viewmodel = new pipelineviewmodel         {             pipenewleads = db.webleads             .where(l => l.loanagent.equals(loanagent) && l.status.equals("new")).tolist(),              pipedispleads = db.webleads             .where(l => l.loanagent.equals(loanagent) && l.status.equals("disp")).tolist(),          };         return view(viewmodel); 

i know controller wrong. need referencing viewmodel somehow, have tried few ways , keep getting errors.

in view, used

@model loanmodule.viewmodels.pipelineviewmodel 

and tried call each list this, didn't work.

@foreach (var item in model.pipenewlead) @foreach (var item in model.dispnewlead) 

i think there, not sure doing wrong in controller. appreciate or references!

consdering have:

public actionresult index(string loanagent) {     var viewmodel = new pipelineviewmodel     {         pipenewleads = ....         pipedispleads = ....      };     return view(viewmodel); } 

your view foreachs should be:

@foreach (var item in model.pipenewleads) @foreach (var item in model.pipedispleads) 

note spelling ;-)

this works fine me:

    public actionresult contact()     {         var viewmodel = new pipelineviewmodel         {             pipenewleads = new list<weblead>(),             pipedispleads = new list<weblead>(),         };         return view(viewmodel);     } 

and view:

@model webapplication1.controllers.pipelineviewmodel @foreach (var item in model.pipedispleads) {     <p>disp</p> } @foreach (var item in model.pipenewleads) {     <p>new</p> } 

your issue somewhere else.

i would:

  1. look @ referencing ienumerable<pipelineviewmodel> , find out why. in different razor view, therefore making error unrelated.
  2. check entity framework returning. ef error getting because either:
    • database not available
    • ef model different database
    • login issues
    • network issues

obviously ef error different, suggestions


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -