I want to have a column as row number in MVC WebGrid. How can I do it?
I want to have a column as row number in MVC WebGrid. How can
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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: