1

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.