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 8468749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:01:27+00:00 2026-06-10T16:01:27+00:00

Im binding data from database to webgrid, i want to keep an actionlink edit

  • 0

Im binding data from database to webgrid, i want to keep an actionlink edit in every row of webgrid, tried the below one but getting error as Object reference not set to an instance of an object near the below line, my model name is User

foreach(var item in Model)

im also posting the whole code

var grid = new WebGrid(source: MvcPopupGrid.Models.User.Users, rowsPerPage: 5);
@grid.GetHtml(
    tableStyle: "grid", headerStyle: "gridhead", footerStyle: "paging", rowStyle: "td-dark", alternatingRowStyle: "td-light",
        columns:
             grid.Columns(
             grid.Column(header: "Id", format: @<text><label id="lblId" title="@item.Id">@item.Id</label></text>),
             grid.Column(header: "Name", format: @<text><label id="lblName" title="@item.Name">@item.Name</label></text>),
             grid.Column(header: "College", format: @<text><label id="lblCollege" title="@item.College">@item.College</label></text>),
             grid.Column(header: "PassedOut", format: @<text><label id="lblPassedOut" title="@item.PassedOut">@item.PassedOut</label></text>),
             grid.Column(header: "Mobile", format: @<text><label id="lblMobile" title="@item.Mobile">@item.Mobile</label></text>)))
foreach(var item in Model)
{
    @item.Id
    @item.Name
    @item.College
    @item.PassedOut
    @item.Mobile
    @Html.ActionLink("Edit", "UserEdit", new { Id = "@item.Id" }, new { @class = "abookModal", title = "Edit User" })
}
  • 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-06-10T16:01:28+00:00Added an answer on June 10, 2026 at 4:01 pm

    Your model is null. I guess that your view is strongly typed to some collection:

    @model IEnumerable<SomeType>
    @foreach (var item in Model)
    {
        ...
    }
    

    except that inside the controller action that rendered this view you didn’t pass any model to the view or you passed null. So make sure that this doesn’t happen:

    public ActionResult SomeAction()
    {
        IEnumerable<SomeType> model = ... fetch the collection from somewhere and make sure this collection is not null
        return View(model);
    }
    

    Another thing I am noticing is that you are pointing your WebGrid source to some MvcPopupGrid.Models.User.Users property:

    var grid = new WebGrid(source: MvcPopupGrid.Models.User.Users, rowsPerPage: 5);
    

    You should also make sure that this property doesn’t return null.

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

Sidebar

Related Questions

I am retrieving data from an Oracle database and binding the same to a
I'm extracting data from the database into a DataTable and displaying it by binding
I have a listview in which i am binding data from database. i have
hi i have datagridview name data1, and binding data to data1 from database, when
I am having trouble binding some data from my MySQL database to a DataGridView
I'm using binding machanism to show data from database table in jTable. I've had
I am retrieving data from sql database. I want to split the records and
How do I use data-binding from code (C# or VB)? This is what I
I need to populate a .net DataGridView from a collection physically (without data binding)
I took the example code from the Kendo UI demos at http://demos.kendoui.com/web/grid/remote-data.html , binding

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.