Congratulations - C# Corner Q4, 2022 MVPs Announced
Why Join
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
Shilin TS
2.2k
21
551
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
<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
//code for checking balance ...........................
[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>
Reply
Answers (
1
)
Datalist inside gridview with no records
how to run unit test cases from asp.net core and angular app