Imran Luhur Imran Luhur - 2 months ago 29
C# Question

How to add a hidden field inside webgrid column in MVC action

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();


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"+" />   ) );