2

In my application , i am using clienside validation to validate particular controls which are rendered from partial view.Partial view coding :

   <fieldset>
   <div>
      <div>
         <%= Html.LabelFor(model => model.OrderID) %>
   </div>
   <div class="editor-field"> 
         <%=Html.DisplayFor(model => model.OrderID)%>
         <%= Html.TextBoxFor(model => model.OrderID) %>
         <%= Html.ValidationMessageFor(model => model.OrderID) %>
   </div>
   </div>
   <fieldset>

After rendering this partial view . i added this with form.

Its not working properly(didnot display error message) when the controls are render in partial view. Then i render this control in normal view its working fine.

    <add key="ClientValidationEnabled" value="true"/>  
    <add key="UnobtrusiveJavaScriptEnabled" value="true">

After i set UnobtrusiveJavaScriptEnabled is false . then i put my control in partial . now its working. but it is not proper way.i want to do it in proper way .

Any idea about this.

sorry i forgot one thing when i was using html begin form in inside partial view with UnobtrusiveJavaScriptEnabled= true . that time also it working.

1
  • @Jonathan Yeah. You need to give 110%!
    – Dismissile
    Dec 5, 2011 at 18:44

2 Answers 2

1

Make sure your field is inside a form because validation messages don't render if the field is not inside a form.

If it is not the reason, show us the validation attribute you're using for this field.

Edit: Maybe obvious, but check that the unobstrusive .js scripts are being loaded. Put the link right in the place that the fields are being validated to confirm it.

Edit 2: Look at the generated html code. Check if the validation messages are beging generated or not. The Rick Anderson idea also seems to be a good starting point in order to find the problem.

2
  • Hi jonathan , thanks for your update i check field is in inside the form. > [Required(ErrorMessage = "Order ID is required.")] public int OrderID { get; set; } Dec 5, 2011 at 18:08
  • i checked that script is perfectly loaded. is any other suggestion Dec 6, 2011 at 9:35
1

Do a view source for the working version and the non-working version and compare. That will show you what you are doing wrong. A partial view should be no different than a view that contains the partial markup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.