ASP. net mvc running Uncaught TypeError: Cannot set property _ MVC

Source: Internet
Author: User

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 ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.