Imran Luhur Imran Luhur - 1 year ago 359
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();

Answer Source

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"+" />   ) );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download