title: MVC Razor WebGrid Get Selected Row on Button Submit
body: <p>How can i get WebGrid Selected Row into Hidden Variable.</p>
  
  <p>I am using the following code.</p>
  
  <pre><code>@{
  var grid = new WebGrid(@ViewBag.ImageFiles, canPage: false, rowsPerPage: 5, selectionFieldName: "SelectedRow", ajaxUpdateContainerId: "gridImages");
  }
  &lt;div id="gridContent"&gt;
  @grid.GetHtml(tableStyle: "webGrid",
              htmlAttributes: new { id = "gridImages" },
              headerStyle: "header",
              displayHeader: true,
              alternatingRowStyle: "alt",
              selectedRowStyle: "select",
              columns: grid.Columns(
              grid.Column("Select", format: (item) =&gt; item.GetSelectLink("Select")),
              grid.Column("File", "Image")))
  &lt;/div&gt;
  &lt;input type="button" value="Submit" onclick="javascript getSelectedRow();"/&gt;
  @{
  System.Dynamic.ExpandoObject expobject = null;
  if (grid.HasSelection)
  {
      expobject = (System.Dynamic.ExpandoObject)grid.SelectedRow.Value;
  &lt;input type="hidden" id="hdnSelectedRow" name="hdnSelectedRow" value="@(expobject == null ? "" : expobject.FirstOrDefault().Value.ToString())" /&gt;
  }
  }
  </code></pre>
  
  <p>Here i am binding Datatable to Webgrid from the following code</p>
  
  <pre><code>foreach (DataRow row in imageFiles.Rows)
          {
              var obj = (IDictionary&lt;string, object&gt;)new ExpandoObject();
              foreach (DataColumn col in imageFiles.Columns)
              {
                  obj.Add(col.ColumnName, row[col.ColumnName]);
              }
              result.Add(obj);
          }
          ViewBag.ImageFiles = result;
  </code></pre>
  
  <p>When i click on submit button i am not getting hidden variable and value in javascript.</p>