title: Searching a record by name and id
body: <p>I'm working with ASP.Net MVC with SQL server management studio.
  Now how would I get a record by a given name and/or id?</p>
  
  <p>Currently, I only find a record using the id which just works fine, but when searching a record by name, it won't find the correct record.</p>
  
  <p>My current code looks something like this:</p>
  
  <pre><code>//Student.cs
  
  public partial class Student
  {
      public int No { get; set; }
      public string Name { get; set; }
      public string Address { get; set; }
      public Nullable&lt;decimal&gt; mobileno { get; set; }
      public string Image { get; set; }
  }
  </code></pre>
  
  <pre><code>//Index.cshtml
  
  @using (Html.BeginForm("search", "CrudManually", FormMethod.Post))
  {
       @Html.TextBox("id")&lt;br/&gt;
       @Html.TextBox("searchString")&lt;br/&gt;
       &lt;input type="submit" value="Search"/&gt;
  }
  </code></pre>
  
  <pre><code>//CrudManuallyController.cs
  
  public class CrudManuallyController : Controller
  {
      public ActionResult Index()
      {
  
          return View(db.manages.ToList());
          //return View();
      }
  
      [HttpPost]
      public ActionResult search(int id,string searchString,Student students)
      {
  
              var query = db.students.Where(d =&gt; d.No == id).AsQueryable();
  
              if (!string.IsNullOrEmpty(searchString))
              { 
                  query = query.Where(d =&gt; d.Name.Contains(searchs)); // generate an error local variable 'searchs' before it is declared.
              }
  
              var  searchs = query.ToList();
              return View("index",searchs);
  
  
      }
  }
  </code></pre>
  
  <p>Now how would I query for an id and a name at the same time?</p>