Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6837961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:32:22+00:00 2026-05-26T23:32:22+00:00

I am new to ASP.NET MVC 3. I am trying to create a basic

  • 0

I am new to ASP.NET MVC 3. I am trying to create a basic WebGrid to try and learn how this works. Currently, I have the following code:

@{
    ViewBag.Title = "Home Page";
}

<h2>@ViewBag.Message</h2>
<p>
@{
    var grid = new WebGrid();
}
@grid.GetHtml()
</p>

When I run this code, I receive an error that says: “A data source must be bound before this operation can be performed.”. My question is, how do I bind this WebGrid to some client-side JSON. I don’t have a back-end database. I’m just trying to learn about the WebGrid without having to wireup a database.

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:32:23+00:00Added an answer on May 26, 2026 at 11:32 pm

    As always in an ASP.NET MVC application you start with a view model:

    public class MyViewModel
    {
        public int Foo { get; set; }
        public string Bar { get; set; }
    }
    

    then a controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var model = new[]
            {
                new MyViewModel { Foo = 1, Bar = "bar 1" },
                new MyViewModel { Foo = 2, Bar = "bar 2" },
                new MyViewModel { Foo = 3, Bar = "bar 3" },
            };
            return View(model);
        }
    }
    

    and finally a corresponding view (~/Views/Home/Index.cshtml):

    @model IEnumerable<MyViewModel>
    @{
        var grid = new WebGrid(Model);
    }
    @grid.GetHtml()
    

    So as you can see the data source of the grid is actually the view model that the controller populated and passed to the view. The actual data could come from anywhere. It’s the controller’s responsibility though to populate the view model and pass it to the view.

    And to learn more about the WebGrid control you may take a look at the following article. And here’s another one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a new asp.net mvc project and i am trying to figure out
I'm new to ASP.NET MVC. I'm currently using ASP.NET MVC 3. I'm trying to
I am new to ASP.NET MVC. I am trying to create what I thought
I'm new to ASP.NET MVC and I'm trying to create a very simple blog
I've been learning asp.net mvc 3. So, basically I'm trying to create a new
I have a Create New Employee ASP.Net MVC form. My complex object is an
I am trying to create a multiline Textbox using ASP.NET MVC with the following
I'm trying to learn the new ASP .NET MVC framework and would like to
I am using ASP.NET MVC . I am trying to create 2 new records
I'm trying to create a ASP.NET MVC 2 webapp using the Northwind database following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.