Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi Team

I want to find out how to validate Textbox, when a radio button is selected in asp.net mvc. I have this controls on the View side, need some help around jquery side. Because it must first validate when a user uses incorrect email address, once correct email is used there wont be any error message to the textbox.

What I have tried:

<div class="modal-body">
                                    <label for="Text" class="col-sm-2 col-form-label">Add users by</label>
                                    <div class="form-group row">
                                        <div class="col-sm-4">
                                            <input type="radio" id="EmailAddress" name="choose" />
                                            <label for="EmailAddress" class="col-form-label">EmailAddress</label>
                                        </div>
                                        <div class="col-sm-3">
                                            <input type="radio" id="LoginID" name="choose" />
                                            <label for="LoginID" class="col-form-label">LoginID</label>
                                        </div>

                                        <div class="col-sm-3">
                                            <input type="radio" id="SIS_ID" name="choose" />
                                            <label for="SIS_ID" class="col-form-label">SIS_ID</label>
                                        </div>

                                        <div class="col-sm-12">
                                            @Html.TextAreaFor(m => m.eNtsaAdmin.eNtsaTextAreaDisc, new { @class = "form-control", style = "font-size: medium; font-weight: bold; width:450px", id = "eNtsaTextAreaDisc" })

                                        </div>
                                        <hr />


                                    </div>
Posted
Comments
Sandeep Mewara 13-Oct-20 8:35am    
I would suggest let MVC handle the validation. SHow/Hide of textbox can be done using jQuery.

Similar approach discussed here: javascript - How to display and validate textbox based on radio button selected - Stack Overflow[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900