Shilin TS

Shilin TS

  • NA
  • 21
  • 723

Data validation

Sep 7 2017 3:26 AM
Hi
 
I am building a web application. I want to make sure that the entered amount should be below available amount. I am not able to do this validation, I am using entityframework 6, MVC and C#. Is it possible to do this with $("#Id").change(function (). I would we glad if somebody help me to resolve this.
 
Thank you
 
My view has
  1. <div class="form-group">  
  2. @Html.LabelFor(model => model.Amount, htmlAttributes: new { @class = "control-label col-md-2" })  
  3. <div class="col-md-10">  
  4. @Html.EditorFor(model => model.Amount, new { htmlAttributes = new { @class = "form-control" } })  
  5. @Html.ValidationMessageFor(model => model.Amount, ""new { @class = "text-danger" })  
  6. </div>  
  7. </div>  
Controller has
  1. //code for checking balance ...........................  
  2. [HttpGet]  
  3. [OutputCache(Duration = 0)]  
  4. public JsonResult CheckAmount(Decimal Amount)  
  5. {  
  6. Decimal amt = Amount;  
  7. long MaxTrNo = db.CashBalances.Max(m => m.TRRecordNo);  
  8. var v = db.CashBalances.Where(m => m.TRRecordNo == MaxTrNo).Select(m => m.CashInHand);  
  9. decimal MaxCashInHand = v.FirstOrDefault().Value;  
  10. string msg = "";  
  11. if (MaxCashInHand <= amt)  
  12. {msg = "Sufficient fund"; }  
  13. else  
  14. {msg = "InSufficient fund"; }  
  15. return Json(msg, JsonRequestBehavior.AllowGet);  
and Script in View has the following
  1. <head>  
  2. <script src="~/Scripts/jquery-3.1.1.js"></script>  
  3. <script type="text/javascript">  
  4. $(function () {  
  5. $("#Amount").change(function () {  
  6. //????????????  
  7. //??????????????  
  8. });  
  9. });  
  10. </script>  
  11. </head>

Answers (1)