Reputation: 4291
I have started to create my first and small MVC4 website. On the home page I would like to have several asp:GridView controls. In the HomeController / ActionIndex method I managed to collect the data (List of objects) that I'm passing to its View through ViewData. Now I stucked here. How can I use these list of objects as the DataSource of the GridView controls?
public ActionResult Index()
{
JenkinsClient client = new JenkinsClient("http://localhost:8080");
bool isJenkinsOnline = client.IsJenkinsOnline();
if (isJenkinsOnline)
{
var jobs = client.GetJobs();
var builds = client.GetBuilds();
ViewData["Jobs"] = jobs;
ViewData["Builds"] = builds;
}
return View();
}
Should I use another approach? I prefer ASPX than Razor.
Upvotes: 1
Views: 2293
Reputation: 1038720
On the home page I would like to have several asp:GridView controls.
Oops, there's no such notion as asp server side controls in ASP.NET MVC! You can forget about controls. ASP.NET MVC is an entirely different pattern. There's no such notion as ViewState and PostBacks, so server side controls simply cannot work in MVC.
In ASP.NET MVC you could use helpers. For example the WebGrid
helper is something that would allow you to build a grid. Here's an article on MSDN
that illustrates the usage of this helper.
I would also recommend you getting through the ASP.NET MVC getting started tutorials here
and familiarize with the basic concepts.
Upvotes: 2