MVC WebGrid Set the ID rendered

Somedeveloper picture Somedeveloper · Jan 24, 2012 · Viewed 10.6k times · Source

Using WebGrid from MVC 3 how do i specify the name of the control when rendered i.e. the id of the table when rendered??

var someGrid = new WebGrid(source: Model.Users, defaultSort: "Name", rowsPerPage: 50);

At the moment when rendered as a table it is displaying as

<table class="grid">

with no id set, i want to access this table using jQuery id selector but cant. Any help appreciated.

What i want is <table id="someIDWhichIset">

Thanks Niall

Answer

markS picture markS · Feb 16, 2012

when you're rendering your table is when you give it the id. @someGrid.GetHtml(htmlAttributes: new {id ="someIDWhichIset"}, columns: ....