asp.net - Check in javascript code if object from session is exist -
in view.cshtml have section check if in session exists object named reservation
<head> @scripts.render("~/bundles/jquery") @scripts.render("~/bundles/jqueryval") <script type="text/javascript"> $(function () { if ( @session["reservation"] ) { $('.reservationdetails :input').attr("disabled", false)); $('#termsection :input').attr("disabled", true); } }); </script> </head> when first time page loaded button id termsection active, when in other action save object reservation in session button still active redirects view.cshtml. think problem lies in condition check if object sesssion null.
i suggest move if condition server side. if reservation isn't present, don't render javascript @ all.
so, instead of
if ( @session["reservation"] ) use
@if ( session["reservation"] != null ) in context:
@if ( session["reservation"] != null ) { $('.reservationdetails :input').attr("disabled", false)); $('#termsection :input').attr("disabled", true); } if reservation not null, output javascript be:
$(function () { $('.reservationdetails :input').attr("disabled", false)); $('#termsection :input').attr("disabled", true); } if reservation null, output javascript be:
$(function () { } in other words, won't anything, seems intention.
Comments
Post a Comment