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

1
  • You may need the <table> tag, jQuery and some Ajax... Commented Feb 21, 2013 at 19:18

3 Answers 3

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

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

Comments

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?

2 Comments

I need to add a grid, and i need to know possible ways i could add it. One way is using Javascript. What are the other ways i could use to do it ?
Do it when you render your HTML.
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?

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.