Sagar Bandkar

Sagar Bandkar

  • NA
  • 190
  • 9.1k

Webgrid Exception in mvc

Oct 25 2016 5:49 AM
Exception:-A data source must be bound before this operation can be performed.
 
I am using webgrid to display data and i am using validation ,when my code (vcCtgCode) is null 
 it display above exception ,How to Overcome the exception.
 
 
@model IEnumerable<******.Model.tblMstCategory_CTG>
<div>
@{
var grid = new WebGrid(Model, ajaxUpdateContainerId: "inCtgId");
@grid.GetHtml(
tableStyle: "webgrid-table",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
selectedRowStyle: "webgrid-selected-row",
rowStyle: "webgrid-row-style",
htmlAttributes: new { id = "Grid" },
//mode: WebGridPagerModes.All,
columns: new[]
{
grid.Column("inCtgId",header:"Id")
,grid.Column("vcCtgCode",header:"Code",format: (item)=> string.IsNullOrEmpty(item.vcCtgCode)?string.Empty:item.vcCtgCode)
})
}
</div>
 

Answers (3)