Chrome prompt:
Determine that the relevant JS is already included in the page (MasterPage is used, and the two pages contain the same js file). This eliminates the incorrect js reference path.
The mvcClientValidationMetadata generated on the page is okay, but the client verification does not work.
Replace MicrosoftAjax. js with MicrosoftAjax. debug. js. The exception is thrown in the Sys. UI. DomElement. getElementById function in the Chrome debugging tool.
Add a breakpoint to row 3, refresh the page, and track the page step by step,
Row 3 gets a DOM object based on the ID. here we can see that optionsFormID is null. (Chrome has a strong js debugging function), and then you can see the previous step of CallStack.
MvcClientValidationMetadata verified by the client after the page is loaded.
You can probably guess where the problem is.
View the page source code. In the script after the </form> node, the generated verification code is as follows:
The Form ID is null!
Then I open the page for difficult client Verification:
The difference is that FormID is null.
And the forms they generate are also different:
Form that cannot be verified by the client
Form that can be verified by the client
An id-based Form can be used for client verification!
However, using (Html. BeginForm () {} is used in both views to generate a Form. We didn't specifically set the Form ID attribute. Why does one have an id and the other has no id?
Cup!
Open the two views page, troubleshoot one by one, and find that the difference between the two views is as follows:
Before BeginForm (), Html. EnableClientValidation (); is called before BeginForm ();
Remember, to use mvc client side validation, call Html. EnableClientValidation () before ininform ();