asp.net mvc 4 - knockout Validation - passing parameter from server side -
i working knockout in mvc application. using knockout validation validating input. fine,my problem is,i have range validator input ll coming server view model.
how can make range validators minimum , maximum validation criteria?
since having code in separate js file cant use @ attribute.
depending on how code set up, can use @
attribute (razor code) said. set local variable on page, run code that's in external file, this, in external js file, can access min
, max
.
@* razor .cshtml page *@ <script type="text/javascript"> var min = @viewbag.min; var max = @viewbag.max; </script> <script type="text/javascript" src="../js/your-external-js"/>
or, keep things clean, use initialize function:
@* razor .cshtml page *@ <script type="text/javascript" src="../js/your-external-js"/> <script type="text/javascript"> $(function() { var min = @viewbag.min; var max = @viewbag.max; myexternaljs.initialize(min, max); }); </script>
Comments
Post a Comment