Skip to content

How to show two different table views in a view in MVC?

Jaima Joseph

Asked Jan 14, 2014, 12:24 AM EST1 answer
Share
LinkedInX

Hi,Can anyone help?I have a table with many records which are having 'Approved' column value  either 'true' or 'false'. I want to show all the records with Approved column value 'true' in a table and all the records with Approved column value 'false' in another table in the same view. I have two vertical tabs 'Approved' and 'Not Approved'. On click of Approved tab, I want to Show the Approved records table and on click of 'Not Approved' I want to show the not approved records table. Please tell me how to pass these two set of records from the controller to the same view? Is that possible?

Thanks in advance.
 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Dharmendra Singh
    0
    you can use ViewBag for returning value and access through foreach on view,

    Suppose I have a simple records
    Id    Name    Status
    1     Ram      true
    2     Shyam   false

    on model

    public ABC
    {
    public int Id{get; set;}
    public string Name{get; set;}
    public bool Status{get; set;}
    }

    on Controller

    List<ABC> items=new List<ABC>();
    items.Add(new ABC{Id=1,Name="Ram",Status=true});
    items.Add(new ABC{Id=2,Name="Shyam",Status=false});
    ViewBag.dyProp = items;

    you should use on view



    @foreach(var item in ViewBag.dyProp)
    {
    if(item.Status)
    {
    // add approved values
    }
    }


    @foreach(var item in ViewBag.dyProp)
    {
    if(!(item.Status))
    {
    // add not approved values
    }
    }
    0