1

I am really new in ASP.Net MVC 4. I need to Display columns and their data in a grid -or webgrid or what- in a page of web application. I should implement the application by Asp.net MVC 4, Visual Studio 2012.

Any help or source to guide me?

Env. SQL server 2012 Visual Studio 2012

1 Answer 1

2

Considering that you have a data model based on that database (use Entity Framework), you can achieve that by using regular HTML tables, on your view (let's call it Table.cshtml):

@model IEnumerable<YourModelClass>

<!-- Using Regular HTML Tables -->
<table>
<tr>
    <th>
        @Html.DisplayNameFor(model => model.FirstOrDefault().Property1)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.FirstOrDefault().Property2)
    </th>
    (...)
</tr>

@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Property1)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Property2)
        </td>
        (...)
    </tr>
}

In your YourModel controller you have something like:

public ActionResult Table()
{
    return View("Table", db.YourModel.ToList());
}

This is pretty simple, and is usually generated by scaffolding. I don't know if this fits your purpose.

This is a good tutorial for begginers: http://www.asp.net/mvc/tutorials/mvc-music-store

Other than that, there's plenty of good "grid" components around the Web with all sorts of "fancy features" like sorting/filtering/etc. (e.g.: I've used DevExpress).

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.