Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
Now it's all clear. – papaiatis Jun 14 at 12:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.