Uncaught TypeError: Cannot set property 'unobtrusive' of undefined

Total Post:3

Points:21
C#
 550  View(s)
Ratings:
Rate this:

Hi Expert,

I having a trouble when implementing validation javascript file in my razor view. Following error is thrown while we run the project.

Uncaught TypeError: Cannot set property

Here is my code,


<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>

<div class="col-md-6">
               <label for="name">Name</label>
               @Html.TextBoxFor(x => x.Name, new { @maxlength = 50, @autofocus = "autofocus", @class = "form-control", placeholder = "Name" })
               @Html.ValidationMessageFor(x => x.Name)
 </div>

Please give me the solution to remove this error and implement validation successfully.

  1. Post:44

    Points:310
    Re: Uncaught TypeError: Cannot set property 'unobtrusive' of undefined

    Hi Sophie,

                    After analyzing your code, I saw you are using your javascript file in wrong way.

    Please rearranged your javascript file in the following manner to accomplish your task,

    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>
    
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script>

    <div class="col-md-6">
                   <label for="name">Name</label>
                   @Html.TextBoxFor(x => x.Name, new { @maxlength = 50, @autofocus = "autofocus", @class = "form-control", placeholder = "Name" })
                   @Html.ValidationMessageFor(x => x.Name)
     </div>

    I Hope its informative for you...

Answer