title: How to Remove white Spaces in my Input Text Box after Data Entry in View page before the form gets submitted MVC ASP.NET?
body: <p>How to do trimming empty Spaces in this Question?I did tried custom binder.Can somebody help me out?I have validated input fields .Later I noticed someone can just enter white space and submit the form. Can someone help me remove white space before text gets submitted. </p>
  
  <p>//Model for Coupon<br>
  <strong>Model:</strong></p>
  
  <pre><code>public int CouponId { get; set; }
  
  [Required]
  public string CouponCode { get; set; }
  
  [Required]
  public int? Discount { get; set; }
  
  public List&lt;CouponModel&gt; GetList()
  {
      List&lt;CouponModel&gt; couponList = new List&lt;CouponModel&gt;();
      couponList = db.Coupons.Select(m =&gt; new CouponModel
      {
          CouponId = m.CouponId,
          CouponCode = m.CouponCode,
          Discount = m.Discount
      }).ToList();
     //Trim White spaces in Coupon Text box
  </code></pre>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>div class="row"&gt;
  @if (ViewBag.Message == null)
  {
      &lt;div class="col-md-8"&gt;
          @using (Html.BeginForm())
          {
              &lt;div class="input-group"&gt;
                                    &lt;input id="CouponCode" name="CouponCode" type="text" class="form-control" placeholder="Coupon Code"&gt;
                  &lt;span class="input-group-btn"&gt;
                      &lt;button id="btnApply" class="btn btn-default" type="submit"&gt;Apply Coupon&lt;/button&gt;
                  &lt;/span&gt;
              &lt;/div&gt;
          }
  
      &lt;/div&gt;
  }
  &lt;div class="col-md-4"&gt;
      @ViewBag.Message
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>//My controller for action
  Controller:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Index(string CouponCode)
  {
      CouponModel model = new CouponModel();
      var cart = (CartModel)System.Web.HttpContext.Current.Session["cart"];
      var coupon = model.GetList().FirstOrDefault(m =&gt; m.CouponCode == CouponCode);
      if (coupon != null)
      {
          cart.CouponApplied = true;
          cart.CouponId = coupon.CouponId;
          cart.CouponCode = coupon.CouponCode;
          cart.Price = cart.Price - cart.Price * 20 / 100;
          cart.Total = cart.Price * cart.Quantity;
          System.Web.HttpContext.Current.Session["cart"] = cart;              
  
          ViewBag.Message = "Coupon is applied Successfully";
      }
      else
      {
          ViewBag.Message = "Coupon not found or Expired!";
      }
      return View(cart);
  }
  </code></pre>