0

I have two datatables loaded with data in MVC view

DataTable dtGrpDisplays= ViewBag.SubGrpDisplayDocs as DataTable;
DataTable dtDownloads= ViewBag.DownloadRequirements as DataTable;

dtGrpDisplays has records - CityId , Display Document Path, Group Id
dtDownloads has records - CityId, Download document Path, Group Id

I needs to display the Display Document first and then the download documents for that group Id.

In View , I have the following Code to display the Display Document

@{  for (int i = 0; i < dtGrpDisplays.Rows.Count; i++)
  {
        <div class="form_header"><h3>   @dtGrpDisplays.Rows[i]["UploadTitle"].ToString() </h3></div>
        <div id ="@i">
        <iframe src="@dtGrpDisplays.Rows[i]["UploadPath"].ToString()" Id="@dtGrpDisplays.Rows[i]["Id"].ToString()"   class="iframe"  scrolling="no" width="100%" marginwidth ="0" marginheight="0" style="border:none;top:auto;"></iframe>

        </div>
  }
}

Now, my issues, how can i write a inside for loop to display the downloadable documents for that particular group Id from Datatable dtGrpDisplays.

I am quite new to MVC. Please help me with a solution.

Is this possible?

Thanks

Marian Ban
  • 8,158
  • 1
  • 32
  • 45
Lax
  • 115
  • 1
  • 1
  • 12
  • 1
    Your `DataTables` aren't connected, so this will be quite hard and add a lot of messy processing to the View. You would be better off processing these in your Controller to create a model class which contains all the info for a group in one object. – Rhumborl Nov 18 '14 at 13:01
  • thanks...but is there any code that I can refer to..please can you help me with any. – Lax Nov 18 '14 at 13:11
  • http://stackoverflow.com/questions/11064316/what-is-viewmodel-in-mvc – DLeh Nov 18 '14 at 13:30

1 Answers1

0
var SubGrpDisplayDocs = (from m in dtGrpDisplays.AsEnumerable()                        
                                            select m).ToList();

var DtDownloads = (from m in DtDownloads.AsEnumerable()
                                    select m).ToList(); 

ViewBag.Data = from m in SubGrpDisplayDocs
                                join n in DtDownloads on m.GroupID equals n.GroupID
                                where m.GroupID = n.GroupID
                                select m;    

Do this LINQ in the Controller (ActionResult) part of your Application then do a forloop in the View part using Razor to loop the Viewbag. If you don't know LINQ I suggest you study it. It will make querying much easier

  • Thanx...did the same in controller. var innerjoinqry = from e in querym join f in queryn on e.tbl_id equals f.tbl_parentId1 select new { id_ = e.tbl_id, uploadpath_ = e.tbl_path, uploadtitle_ = e.tbl_title, idparent_ = f.tbl_parentId1, subdoctitle_ = f.tbl_title1, subdocpath_ = f.tbl_path1 }; But, I am not able to work about with the for loop in View. My purpose is to display the contents of the main group-querym as iframe source and after that display the downloadable docs.. – Lax Nov 20 '14 at 18:58
  • Won't this have as many div sections as the display documents?? please help... I am stuck with this issue for more than 2 days now...phew..cant find any solution.. – Lax Nov 20 '14 at 19:03
  • Hi, is there any solution for this? – Lax Nov 21 '14 at 12:45