title: How to search by ID in MVC
body: <p>I wanted to know if there is a way to search records by ID in MVC
  I have seen some examples but most use String and my field is Decimal, this is what I am looking for.
  Basically I need to filter my records using the ID in a TextBox</p>
  
  <pre><code>localhost/Search?req_no=1
  </code></pre>
  
  <p>I have the following code but I don't know if it's correct, Thank you.</p>
  
  <p>Controller</p>
  
  <pre><code>    namespace MvcApplication31.Controllers
  {
      public class SearchController : Controller
      {
          //
          // GET: /Search/
  
          public ActionResult Search()
          {
              Entities db = new Entities();
              return View(db.TB_CS_TEST.ToList());
          }
          [HttpPost]
          public ActionResult Search(decimal? reqid)
          {
              Entities db = new Entities();
              var req = from r in db.TB_CS_TEST
                        select r;
              if (reqid.HasValue)
              {
                  req = req.Where(s =&gt; s.REQ_NO.Equals(reqid));
              }
              return View(req);
          }
  
      }
  }
  </code></pre>
  
  <p>View</p>
  
  <pre><code>@model IEnumerable&lt;MvcApplication31.TB_CS_TEST&gt;
  
  @{
      ViewBag.Title = "Search";
  }
  
  &lt;h2&gt;Search&lt;/h2&gt;
  
  &lt;p&gt; 
      @Html.ActionLink("Create New", "Create") 
  
       @using (Html.BeginForm("Search","Search", FormMethod.Post)){    
           &lt;p&gt; Request Number: @Html.TextBox("reqid") &lt;br /&gt;   
           &lt;input type="submit" value="Search" /&gt;&lt;/p&gt; 
          } 
  &lt;/p&gt; 
  </code></pre>
  
  <p>Class</p>
  
  <pre><code>    namespace MvcApplication31
  {
      using System;
      using System.Collections.Generic;
  
      public partial class TB_CS_TEST
      {
          public decimal REQ_NO { get; set; }
          public Nullable&lt;decimal&gt; SEQ_NO { get; set; }
          public Nullable&lt;decimal&gt; ITEM_ID { get; set; }
          public Nullable&lt;decimal&gt; QUANTITY { get; set; }
          public string UOM { get; set; }
          public Nullable&lt;decimal&gt; UNIT_PRICE { get; set; }
          public Nullable&lt;decimal&gt; EXTENDED_AMT { get; set; }
          public Nullable&lt;System.DateTime&gt; CRT_DATE { get; set; }
          public decimal REQDTL_ID { get; set; }
  
          public virtual TB_CS_TEST2 TB_CS_TEST2 { get; set; }
      }
  }
  </code></pre>