ViewModels are a way to represent data on a View where you need to display information from Models, please have a look at this question to understand what they are: What is ViewModel in MVC?
In your case you can create a simple ViewModel to represent data that you need to display on Report_Main
, this can be easily achieved by doing:
namespace MyProject
{
public class MyViewModel
{
public int ID { get; set; }
public System_Tracking Tracking { get; set; }
public Report_Login_Credentials Credentials { get; set; }
public Report_Type Type { get; set; }
public List<Report_Peramiter_Fields> Fields { get; set; }
public string Name { get; set; }
public string Location { get; set; }
}
}
It may just look like a simple Model, because it is but it's only used by a view and it is not persisted. That is the difference here between a Model and a View Model.
From this you only need one page, say MyPage.cshtml
where you can use this model like:
@model MyProject.MyViewModel
@{
ViewBag.Title = "MyPage";
}
@* your content here *@
@Model.ID <br>
@Model.Report_Type.Description
// Etc.
To pass this information you will need to do it in your controller, for example:
namespace MyProject
{
public class MyController : Controller
{
public ActionResult MyPage(int? Id)
{
var data = context.Report_Main.Find(Id); // Or whatever
var vm = new MyViewModel(){
Tracking = data.System_Tracking,
// ... populate the viewmodel here from the data received
};
return View(vm);
}
}
}
In short, ViewModels allow you to bind all the data in one Model and pass it onto the view which can statically represent it, and you can also use this when getting data from a user when you don't want direct representation or access to a Model.
Edit: You can iterate through list of models in Razor by using C#:
foreach(var item in Model.Fields)
{
<p>item.Peramiter</p>
}