asp.net - WebForm and MVC Project running side by side. Unobtrusive validation not working -


i have webform project want add mvc 5 new stuff developed mvc. 1 of features use in mvc unobtrusive client side validation. can't seem make work in scenario. validation works in server side not work on client side. inspecting tags notice attributes not being generated. don't have javascript error showing in browser console. if in pure mvc5 project works fine. have idea how can make work? missing something?

the way have been testing is:

  1. i create webform project( using framework 4.5).
  2. i add nuget mvc5 project.
  3. create area.
  4. add arearegistration.registerallareas(); global.asax can use areas.
  5. add nuget:
    • jquery validation
    • microsoft jquery unobtrusive validation
  6. create controller in previous created area , add view.
  7. in web.config of view folder add appsettings:
  8. then create model , add validation.

view index:

@model merda.areas.branchen.models.testmodel  @{     viewbag.title = "index"; }  <h2>index</h2> <script src="~/scripts/jquery-1.8.2.min.js"></script> <script src="~/scripts/jquery.validate.min.js"></script> <script src="~/scripts/jquery.validate.unobtrusive.min.js"></script> @using (html.beginform())  { @html.antiforgerytoken()  <div class="form-horizontal">     <h4>testmodel</h4>     <hr />     @html.validationsummary(true)      <div class="form-group">         @html.labelfor(model => model.prop1, new { @class = "control-label col-md-2" })         <div class="col-md-10">             @html.editorfor(model => model.prop1)             @html.validationmessagefor(model => model.prop1)         </div>     </div>      <div class="form-group">         @html.labelfor(model => model.prop2, new { @class = "control-label col-md-2" })         <div class="col-md-10">             @html.editorfor(model => model.prop2)             @html.validationmessagefor(model => model.prop2)         </div>     </div>      <div class="form-group">         <div class="col-md-offset-2 col-md-10">             <input type="submit" value="create" class="btn btn-default" />         </div>     </div> </div> }  <div> @html.actionlink("back list", "index") </div> 

controller:

public class testcontroller : controller {     //     // get: /branchen/test/     public actionresult index()     {         return view();     }      [httppost]     public actionresult index(testmodel model)     {         if (modelstate.isvalid)         {             modelstate.addmodelerror(string.empty, "valid");         }         else {             modelstate.addmodelerror(string.empty, "error...");          }          return view();     } } 

model created:

public class testmodel {     [required]     public string prop1 { get; set; }     [required]     public string prop2 { get; set; }  } 

web.config inside view folder created.

<?xml version="1.0"?>  <configuration>   <configsections>     <sectiongroup name="system.web.webpages.razor" type="system.web.webpages.razor.configuration.razorwebsectiongroup, system.web.webpages.razor, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35">       <section name="host" type="system.web.webpages.razor.configuration.hostsection, system.web.webpages.razor, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" requirepermission="false" />       <section name="pages" type="system.web.webpages.razor.configuration.razorpagessection, system.web.webpages.razor, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" requirepermission="false" />     </sectiongroup>   </configsections>    <system.web.webpages.razor>     <host factorytype="system.web.mvc.mvcwebrazorhostfactory, system.web.mvc, version=5.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" />     <pages pagebasetype="system.web.mvc.webviewpage">       <namespaces>         <add namespace="system.web.mvc" />         <add namespace="system.web.mvc.ajax" />         <add namespace="system.web.mvc.html" />         <add namespace="system.web.routing" />         <add namespace="system.web.optimization" />         <add namespace="merda" />        </namespaces>     </pages>   </system.web.webpages.razor>    <appsettings>     <add key="webpages:enabled" value="false" />     <add key="clientvalidationenabled" value="true" />     <add key="unobtrusivejavascriptenabled" value="true" />   </appsettings>    <system.webserver>     <handlers>       <remove name="blockviewhandler"/>       <add name="blockviewhandler" path="*" verb="*" precondition="integratedmode" type="system.web.httpnotfoundhandler" />     </handlers>   </system.webserver> </configuration> 

update: using vs2012 porfessional.

you have write keys in main web.config, not inside view folder. can enable validation in per-controller basis, seen in clientvalidationenabled , unobtrusivejavascriptenabled in mvc 4


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -