Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am working with a MVC website project. I have wrote codes for validating certain controls in my view. But while submitting the form these messages are not displayed. and not even go to the controller method if all the fields are entered.

Code in my View
C#
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true);
    <fieldset style="margin: 20px">
        <legend>Contact Us</legend>
        <div class="editor-label">
            <label for="unCandidateFirstName">
                Name</label>
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.unCandidateFirstName)
            @Html.ValidationMessageFor(model => model.unCandidateFirstName)
        </div>
        <div class="editor-label">
            <label for="unCandMobilePhone">
                Mobile No</label>
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.unCandMobilePhone)
            @Html.ValidationMessageFor(model => model.unCandMobilePhone)
        </div>        
        <p>
            <input type="submit" value="Contact Us" />
        </p>
    </fieldset>                                                
}


Please any one help me..
Posted
Updated 5-Nov-14 19:16pm
v2

Make sure that you are done the following things

For enabling client side validation, we required to include the jQuery min, validate & unobtrusive scripts in our view or layout page in the following order
XML
<script src="@Url.Content("~/Scripts/jquery-1.6.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>


We can enable and disable the client-side validation by setting the values of ClientValidationEnabled & UnobtrusiveJavaScriptEnabled keys true or false. This setting will be applied to application level.
XML
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
 
Share this answer
 
Comments
Jineesh TR 6-Nov-14 2:22am    
Thank You Jameel for your support..
Jameel VM 6-Nov-14 2:57am    
welcome..
Yes I agree with Jameel, please do check for the references and also check for the model validation attribute you have used in the view model or not.
Like Required attribute/regular expressions if any. And based on the input, you can also try and apply custom validation message.
C#
ModelState.AddModelError("MODEL PROPERTY","MESSAGE");
return View(model);


Hope this helps.
Post back your queries if any.
Thanks.
 
Share this answer
 
Comments
Jineesh TR 6-Nov-14 2:22am    
Thank You Suraj for your support..

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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