(first time posting and fairly new to MVC) I currently have a MVC/C# application where the user selects a list of ID's and then chooses a Report Type (8 possible different reports calling 8 different database views). I am passing all of these parameters to the controller. Based on the report type chosen, I want to fetch the data, send it back to the view and then display the data in a grid/table format.
I tried sending the data via ViewBag and ViewData but had trouble parsing the actual columns/data using @foreach. This is when I decided to try ViewModels.
//My ViewModel....
//I know that I am missing the {get;set;} code which is where I also
// need help with. I need to pass the selected ID's to each database view and
// perform additional query requests (i.e. Distinct, Order By).
// Sample query:
// var dd = (from p in _db.Report1 select new { sId = p.ReportID, UserName = p.Submitted_By,
// Balance = p.TotalDebt}).Distinct();
// dd = dd.Where(w => chosenUserIDs.Contains(w.sID));
// dd.OrderBy(p => p.sId).ThenBy(p => p.UserName).ThenBy(p => p.Balance);
public class UserReportsViewModel
{
public List<namespace.report1> Report1 = new List<namespace.report1>();
public List<namespace.report2> Report2 = new List<namespace.report2>();
public List<namespace.report3> Report3 = new List<namespace.report3>();
...
}
//My Controller
UserReportsViewModel UserReportVM = new UserReportsViewModel();
switch (reportType)
{
case "REPORT1":
//Pass the selected ID's and get the data back from Report1 db view
// not quite sure how to do this.
break;
case "REPORT2":
break;
case "REPORT3":
break;
default:
break;
}
return View(UserReportsVM);
Am I even on the right track? I also came across something about partial Views and having the View call/referrence the correct partial View (?). Older languages were a lot simpler to accomplish this but I am really liking MVC/.Net/C#.
As for my database, I am using CodeFirst Entity framework.