Display empty data-text in web grid in mvc4

Description:-

In this example we explain that how to display Empty data text in web grid in mvc with asp.net.we already explain that how to display empty data text text in GridView in asp.net but in mvc that is no facility in web grid to display empty data text automatically so we have to manually write or define the code for this.

Let have to see a simple tip that shows how to display Empty Data or empty data text in a ASP.NET MVC 4 WebGrid by using WebGrid web helper class.

Here in this post we will check the model if it has no data then displays a message, similar to the EmptyDataText property of the ASP.NET GridView.

To use the WebGrid web helper in mvc application, you have to first create an object reference to the WebGrid class and use the GetHtml() method that renders the grid.

@{ 
Var grid=new WebGrid(Model); 
@grid.GetHtml(); 
} 

To Display an Empty Data Text in Webgrid when the Model has no data or no record, just you have to write following one:

@if(Model.Count>0) 
@{ 
  Var grid=new WebGrid(Model); 
  @grid.GetHtml(); 
} 
Else 
  <p>No Record Found</p>
} 

Related Posts

Previous
Next Post »

Thanks for comments.....