ASP.NET MVC 3: Display Empty Data Text in WebGrid

Let us see a simple tip that shows how to display Empty Data in a ASP.NET MVC 3 WebGrid. If you are new to the WebGrid Web helper control, I strongly recommend you to read an article by Malcolm on WebGrid WebHelper in ASP.NET MVC 3

In this post, we will detect if the model has no data and display a message, similar to the EmptyDataText property of the ASP.NET GridView.

To use the WebGrid web helper, we will first create an object reference to the WebGrid class and use the GetHtml() method that renders the grid


To add an Empty Data Text when the Model has no data, just replace the above code with the following one:


That’s it! The next time you run your application and if the model has no data in it, the text ‘No Data Found’ will be displayed. Similarly you can display an image or any other HTML text to convey the message.

About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

No comments: