0

My project is a C# MVC web application. In the View, i have created all elements as

<input type="text" id="fname" name="fName" />

instead of using HTML helper tags;

Now, i need to add a Grid, which i could add/update/delete records. How can i add a grid using html as shown in the above code; I should be able to add/remove rows in the grid.

Note: I don't want to use HTML helper to create a grid

user1315906
  • 3,374
  • 8
  • 30
  • 43

3 Answers3

1

What have you tried so far? Also, is there a reason you don't want to use a helper like MvcContrib HTML.Grid? The helpers make things a lot simpler, especially model binding.

If you don't use a helper you'll need to use a foreach loop to build a grid from <table> elements in your view, Something like:

@Model User
       <table id="user-index" >
                <thead>
                <tr>
                    <th>
                       First Name
                    </th>
                    <th>
                       Last Name
                    </th>
                    <th>
                        Phone
                    </th>
                </tr>
                </thead>
                <tbody>
        @foreach (var user in Model.UserList)
        {
             <tr>
                    <td>
                    //I'm using helpers in my example, you can output however you like
                    @Html.DisplayFor(model => user.firstname)
                    </td>
                    <td>
                    @Html.DisplayFor(model => user.lastname)
                    </td>
                    <td>
                    @Html.DisplayFor(model => user.phone)
                    </td>
            </tr>   
        }
            </tbody>
            </table>

There are also jQuery options for grids, take a look at DataTables

Edit: HTML helpers also make it much easier to deal with null values returned by your model

Jack
  • 1,319
  • 8
  • 16
0

It's hard to understand what you are asking here.

In HTML, grids are created using <table> tags. So the answer would be to use a <table> tag.

Where are you getting stuck?

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
0

There are a lot of grid options for MVC you can also create your own but to save time use something like jQuery Grid or Kendo.

This might help you out in choosing what you need grid controls for ASP.NET MVC?

Community
  • 1
  • 1
Raymund
  • 7,684
  • 5
  • 45
  • 78