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
- <div class="form-group">
- @Html.LabelFor(model => model.Amount, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.Amount, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.Amount, "", new { @class = "text-danger" })
- </div>
- </div>
Controller has
-
- [HttpGet]
- [OutputCache(Duration = 0)]
- public JsonResult CheckAmount(Decimal Amount)
- {
- Decimal amt = Amount;
- long MaxTrNo = db.CashBalances.Max(m => m.TRRecordNo);
- var v = db.CashBalances.Where(m => m.TRRecordNo == MaxTrNo).Select(m => m.CashInHand);
- decimal MaxCashInHand = v.FirstOrDefault().Value;
- string msg = "";
- if (MaxCashInHand <= amt)
- {msg = "Sufficient fund"; }
- else
- {msg = "InSufficient fund"; }
- return Json(msg, JsonRequestBehavior.AllowGet);
and Script in View has the following
- <head>
- <script src="~/Scripts/jquery-3.1.1.js"></script>
- <script type="text/javascript">
- $(function () {
- $("#Amount").change(function () {
-
-
- });
- });
- </script>
- </head>