4

I want to create hidden field in Webgrid PollId column which i am exactly not sure how to add some extra fields in this scenario

    public ActionResult Index(string mode)
    {
         List<WebGridColumn> columns = new List<WebGridColumn>();
         columns.Add(new WebGridColumn() { ColumnName="PollId", Header="Id", Format= (item) =>  });
         ViewBag.Columns = columns;
         ViewBag.Columns = columns; 
         return View();
    }
neontapir
  • 4,698
  • 3
  • 37
  • 52
Imran Luhur
  • 447
  • 3
  • 15

3 Answers3

2

You can add hidden field using string.Format in your controller action

columns.Add(new WebGridColumn() { Header = "", Format = (item) => {
    return new HtmlString(  string.Format("<input type="+"hidden"+" value="+"Poll"+" id="+"Mode"+" />   ) );
Dragon
  • 1,078
  • 2
  • 9
  • 31
1

and use a strongly typed helper in your view:

@Html.HiddenFor(x => x.ColumnName, new { id = "ColumnName" })
MMM
  • 3,132
  • 3
  • 20
  • 32
0

You can do one thing to support legacy browsers. You could use jQuery to apply a hidden style to the header and the rows of the first column or to simply hide them directly.

$(function () {
    $('table th:first-child, table td:first-child').hide();
});
Tunaki
  • 132,869
  • 46
  • 340
  • 423
BalaRam
  • 59
  • 7