vendredi 28 août 2015

How to enable and disable MVC Required Field validation

I need to enable and disable the required field validation based on anchor tag click.

Here I showed some example

<div class="row">
        <div class="col1">
            @Html.DisplayNameFor(m => m.CustomText)
        </div>
        <div class="col2">
            @Html.TextAreaFor(m => m.CustomText)
            @Html.ValidationMessageFor(m => m.CustomText, null, new { @style = "color:red" })
        </div>
        <a href="javascript:void(0)" onclick="SelectOn();" class="button">ON</a>
        <a href="javascript:void(0)" onclick="SelectOff();" class="button">OFF</a>
</div>
<script type="text/javascript">
        $(document).ready(function () {
            var modVal = '@Modle.IsEnabled';
            if (modVal = 'false') {
                //Need to disable
            }
        });

        function SelectOn() {
            //Need to enable
        }

        function SelectOff() {
            //Need to disable
        }
</script>

Aucun commentaire:

Enregistrer un commentaire