I want to have a column as row number
in MVC WebGrid. How can I do it?
相关问题
- MVC-Routing,Why i can not ignore defaults,The matc
- Entity Framework throws exception - Network Relate
- parameters in routing do not work MVC 3
- Slow loading first page - ASP.NET MVC
- There is no ViewData item with the key 'taskTy
相关文章
- “Dynamic operations can only be performed in homog
- How to get a list of connected clients on SignalR
- How do you redirect to the calling page in ASP.NET
- Change color of bars depending on value in Highcha
- The program '[4432] iisexpress.exe' has ex
- ASP.Net MVC 4 Bundles
- How to get server path of physical path ?
- Cannot implicitly convert Web.Http.Results.JsonRes
Try this
Add this:
That's a really nice approach, but when you use sorting or paging your
RowNumber
values won't start from 1 on the page.In my project I had a case where I needed to know an index of the row independently of WebGrid's paging / sorting and I came across the following solution:
You could use a view model that will contain a property indicating the row number.
Let's suppose that you have the following domain model:
Now you build a view model that will correspond to the requirements of your view:
and then:
Now your view becomes strongly typed to the view model of course:
Now let's suppose that for some foolish reason you don't want to use view models. In this case you could turn your view into spaghetti code if you prefer:
simply add the following code
Check this link for more info
hope this will be helpful to someone