title: ASP.NET MVC value of a input tag into a sql query
body: <p>I would like to filter my table using a input tag, something like: "SELECT * FROM tblaccount WHERE accountNo = 'document.getElementById('txtSearch').value'"</p>
  
  <p>This is my AccountsViewModel</p>
  
  <pre><code>namespace MyProject.Models
  {
  public class AccountsViewModel
  {
      public DataTable Accounts { get; set; }
  }
  }
  </code></pre>
  
  <p>SelectModel.cs</p>
  
  <pre><code>namespace MyProject.Models
  {
  public class SelectModel
  {
      private static SqlConnection GetCn()
      {
          SqlConnection cn = new SqlConnection(@"MyConnectionString");
          return cn;
      }
  
      public DataSet GetAccounts()
      {
          SqlConnection cn = GetCn();
          SqlCommand cmd = new SqlCommand("SELECT * FROM tblaccount ORDER BY accountNo ASC", cn);
          DataSet ds = new DataSet();
          SqlDataAdapter da = new SqlDataAdapter(cmd);
          da.Fill(ds);
          return ds;
      }
  }
  }
  </code></pre>
  
  <p>HomeController.cs</p>
  
  <pre><code>namespace MyProject.Controllers
  {
  public class HomeController : Controller
  {
      public ActionResult Index(MyProject.Models.SelectModel selectmodel)
      {
          AccountViewModel vm = new AccountViewModel();
          DataSet ds = selectmodel.GetAccounts();
          vm.Accounts = ds.Tables[0];
  
          return View(vm);
      }
  }
  }
  </code></pre>
  
  <p>Index.chtml</p>
  
  <pre><code>@model MyProject.Models.AccountsViewModel
  
  &lt;label for="txtSearch"&gt;Search: &lt;/label&gt;        
  &lt;input type="text" class="form-control" id="txtSearch"&gt;
  &lt;button class="btn btn-default" type="submit" id="btnSearch"&gt;Search&lt;/button&gt;
  
  &lt;table class="table"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;ID&lt;/th&gt;
              &lt;th"&gt;Account Number&lt;/th&gt;
              &lt;th"&gt;Transaction Date&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          @foreach (System.Data.DataRow dr in Model.Accounts.Rows)
          {
      &lt;tr&gt;
          &lt;td&gt;@dr["Id"].ToString()&lt;/td&gt;
          &lt;td&gt;@dr["accountNo"].ToString()&lt;/td&gt;
          &lt;td&gt;@dr["dateTrans"].ToString()&lt;/td&gt;
      &lt;/tr&gt;}
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>