title: Display uploaded data to MVC view and import selected record to database
body: <p>I need to import user uploaded CSV data to database.
  Steps - 
  1. User upload data to MVC View
  2. Display all uploaded data in the View 
  3. User can select the column name based on imported value
  3. Import data based on user selection of the records.</p>
  
  <p>To implement this, I created below Model -          </p>
  
  <pre><code>public class ImportCSVData
  {      
      public IEnumerable&lt;System.Web.Mvc.SelectListItem&gt; Names { get; set;}    // This is to display dynamic column      
      public HttpPostedFileBase File { get; set; }     
      public DataTable Data { get; set; }  
  }  
  </code></pre>
  
  <p>In the controller, I am parsing the uploaded file (sample code)                           </p>
  
  <pre><code>    public ActionResult ImportCSVCustomer()
      {
          ImportCSVData model = new ImportCSVData();
          HttpPostedFileBase upfile = Request.Files["File"];
          model.File = upfile;            
              var dt = ParseCSVData(model);
              if (dt != null &amp;&amp; dt.Rows.Count &gt; 0)
              {                 
                  var dcRec = new DataColumn("ShouldImport", typeof(bool));                 
                  dcRec.DefaultValue = false;
                  dt.Columns.Add(dcRec);         
                  model.Data = dt;
                  List&lt;SelectListItem&gt; Names = getColumnNames();
                  model.Names = Names;                 
                  return PartialView("_ImportedCSVCustomer", model);
              }                      
          return View();
      }
  </code></pre>
  
  <p>Sample View that I designed - </p>
  
  <pre><code>   @for (int i = 0; i &lt; Model.Data.Rows.Count; i++)
     {
     &lt;tr&gt;
      &lt;td data-val="@i"&gt;
      &lt;input type="checkbox" name="sid" value=@Model.Data.Rows[i][Model.Data.Columns.Count - 1] class="sid"&gt;
     &lt;/td&gt;
      @for (int j = 0; j &lt; Model.Data.Columns.Count - 1; j++)
      {
       &lt;td&gt;
           @Model.Data.Rows[i][j].ToString()
           @Html.HiddenFor(Model.Data.Rows[i][j].ToString())
       &lt;/td&gt;
       }
     &lt;/tr&gt;
     }
  </code></pre>
  
  <p>I was working on the view to display, but , unable to get the model value after posting from View to Controller.
  Any idea how to implement this?</p>