Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6587745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:57:26+00:00 2026-05-25T16:57:26+00:00

I have a farily straight forward form that renders personal data as a partial

  • 0

I have a farily straight forward form that renders personal data as a partial view in the center of the form. I can not get client side validation to work on this form.
I started chasing down the generate html and came up with the same model field rendered on a standard form and a partial view.

I noticed that the input elements are correctly populated on the first call, @html.partial, the following only happens when the partialview is reloaded via an ajax request.

First the header of my partial view, this is within a Ajax.BeginForm on the main page.

@model MvcMPAPool.ViewModels.EventRegistration
<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>
<script type="text/javascript">
$(document).ready(function ()
{
    $(".phoneMask").mask("(999) 999-9999");
});
</script>

@{
    var nPhn = 0;
    var dTotal = 0.0D;
    var ajaxOpts = new AjaxOptions{ HttpMethod="Post", UpdateTargetId="idRegistrationSummary", OnSuccess="PostOnSuccess" };
    Html.EnableClientValidation( true );
    Html.EnableUnobtrusiveJavaScript( true );
}

Here is the razor markup from the partial view:

@Html.ValidationMessageFor(model=>Model.Player.Person.Addresses[0].PostalCode)
<table>
    <tr>
        <td style="width:200px;">City*</td>
        <td>State</td>
        <td>Zip/Postal Code</td>
    </tr>
    <tr>
        <td>@Html.TextBoxFor(p=>Model.Player.Person.Addresses[0].CityName, new { style="width:200px;", maxlength=50 })</td>
        <td>
        @Html.DropDownListFor(p=> Model.Player.Person.Addresses[0].StateCode
                                 , MPAUtils.GetStateList(Model.Player.Person.Addresses[0].StateCode))</td>
        <td>
        <div class="editor-field">
        @Html.TextBoxFor(p=>Model.Player.Person.Addresses[0].PostalCode, new { style="width:80px;", maxlength=10 })
        </div>
        </td>
    </tr>
</table>

Here is the rendered field from the partial view:

        <td>
        <div class="editor-field">
        <input id="Player_Person_Addresses_0__PostalCode" maxlength="10" name="Player.Person.Addresses[0].PostalCode" style="width:80px;" type="text" value="" />
        </div>
        </td>

Here is the same model field rendered in a standard view:

        <div class="editor-field">            
            <input data-val="true" data-val-length="The field Postal/Zip Code must be a string with a maximum length of 10." data-val-length-max="10" data-val-required="Postal or Zip code must be provided!" id="Person_Addresses_0__PostalCode" maxlength="10" name="Person.Addresses[0].PostalCode" title="Postal/Zip Code is required" type="text" value="" />       
            <span class="field-validation-valid" data-valmsg-for="Person.Addresses[0].PostalCode" data-valmsg-replace="true"></span>        
        </div>

Notice that the partial view rendering has no data-val-xxx attributes on the input element.

Is this correct? I do not see how the client side validation could work without these attributes, or am I missing something basic here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:57:27+00:00Added an answer on May 25, 2026 at 4:57 pm

    In order to create the unobtrusive validation attributes, a FormContext must exist. Add the following at the top of your partial view:

    if (this.ViewContext.FormContext == null) 
    {
        this.ViewContext.FormContext = new FormContext(); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly straight-forward sequential approval workflow that has an EnableModificationActivity that is
I have a form on a page that is for the most part straight
I have a fairly straight-forward scenario that I am trying to solve but I'm
I have a question which i suspect is fairly straight forward. I have the
My web app, up until this point, has been fairly straight forward. I have
This is a fairly straight forward decorator pattern scenario, with the complication that the
Background: Our app is a fairly straight forward MVC web app that calls a
I currently have a fairly straight forward app, my first attempt at MVVM using
It seemed farily straight forward learning how to process files dropped onto a ListView
I have a fairly straight forward question. I have a commandline application I'm writing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.