none
MVC5 and Database-First (w/ Oracle 12) and Entity Framework 6 and unobtrusive javascript validation does not seem to be working. Anyone experienced/fixed this? RRS feed

  • Question

  • I used the buddy class approach to add data annotation to my db-first EF6 model but I barely got javascript client-side validation to work but now I am wondering why the unobtrusive validation is not working.  

    1. EF6 - buddy class csharp code file...

     [MetadataType(typeof(NOTEMeta))]
        public partial class NOTE
        {
            internal sealed class NOTEMeta
            {
                public decimal NOTE_ID { get; set; }

                [Required(ErrorMessage = "The comment type.")]
                [System.ComponentModel.DisplayName("Type: (req)")]
                public decimal NOTE_CTGY_ID { get; set; }

                [Required(ErrorMessage = "Must be valid date.")]
                [DisplayName("Date: (req)")]
                //[DisplayFormat(DataFormatString = "{0:d}")]
                [DataType(DataType.Date)]
                public System.DateTime NOTE_DT { get; set; }

                [Required(ErrorMessage = "Your {0} is required.")]
                [DisplayName("Title: (req)")]
                [StringLength(40, MinimumLength = 1)]
                public string NOTE_TITLE_NM { get; set; }

                [DisplayName("Comment: (req)")]
                [Required(ErrorMessage = "Your {0} is required.")]
                [StringLength(3999, MinimumLength = 1)]
                public string NOTE_TX { get; set; }

    ...

    }

    2. (mvc views directory) Web.config settings used...

    <appSettings>
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      </appSettings>

    3. (main project) Web.config settings used...

      <appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="false" targetFramework="4.7.1" />
        <httpRuntime targetFramework="4.7.1" />
      </system.web>

    4. _Layout.cshtml file...

        @Scripts.Render("~/bundles/jquery")
        @Scripts.Render("∼/bundles/jqueryval")
        @Scripts.Render("~/bundles/bootstrap")
        @RenderSection("scripts", required: false)
    </body>

    What else might be missing?

    Friday, October 26, 2018 8:33 PM

All replies

  • You may want to also post to the ASP.NET forums.

    http://forums.asp.net/

    Also, I think Oracle provider still I think has problems with EF.

    Friday, October 26, 2018 8:48 PM
  • Thanks. Will do.

    Tomorrow may never come. Thank you for right now.

    Saturday, October 27, 2018 5:17 PM
  • Hi,

    You need three sets of files to implement Unobtrusive:

    The jQuery library
    The jQuery Validate plugin
    The Unotrusive extensions to Validate
    The Unobtrusive script files are included automatically with new MVC projects in Visual Studio, but if you don't have them you can get them from NuGet. 

    at App_Start/BundleConfig.cs 

    add

    public static void RegisterBundles(BundleCollection bundles)

    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate*"));

    }

    Hopefully, will work for you. Thank you

    Wednesday, November 14, 2018 5:54 AM