validation on the local field, dev-site, but this does not happen on intermediate and production sites. Verification on the client side and on the server side does not occur. Both stages and production are load balanced, but use a sticky compound due to some other functional requirements.
I checked the bin folder in all environments, and I see the following two DLLs there.
DataAnnotationsExtensions.ClientValidation.dll DataAnnotationsExtensions.dll
On the server side, the following should fail, but this does not happen.
!TryValidateModel(model) || !ModelState.IsValid
This site uses Windows authentication.
Web.config
<appSettings file="Configs\AppSettings_LocalHost.config"> <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>
For testing purposes, I do not use packages at this time. For packages, I even tested it with the following
<location path="~/Content"> <system.web> <authorization> <allow users ="*" /> </authorization> </system.web> </location> <location path="~/bundles"> <system.web> <authorization> <allow users ="*" /> </authorization> </system.web> </location> <location path="~/Scripts"> <system.web> <authorization> <allow users ="*" /> </authorization> </system.web> </location>
And I have the following JS files, which are also referenced
<script src="/NetSite/Scripts/Core/jquery.validate.min.js?v=1.12" type="text/javascript"></script> <script src="/NetSite/Scripts/Core/jquery.validate.unobtrusive.min.js?v=1.12" type="text/javascript"></script> <script src="/NetSite/Scripts/Custom/Validators.js?v=1.12" type="text/javascript"></script>
The app is MVC 5, and everything has been added through the NuGet package. I do not have MVC installed on the server. I have another MVC 5 application on these servers, and the verification is just fine.
And here is the form tag, the second working application uses the same form tag.
using (Html.BeginForm(ActionNames.Index, ControllerNames.Rankings, new { Area = AreaNames.MemberToolsReports }, FormMethod.Post, new { id = "RankingsSearchForm" }))
Validation was performed on the old intermediate and production units, but MVC 3 was installed on it.
Update - Controller Code
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Project.BusinessEntities; using Project.Common.Constants; using Project.MvcBase; using Project.Resources; using Project.ServiceInterfaces; using Project.ViewModels; using Project.ViewModels.MemberToolReports; using Microsoft.Practices.Unity; using Project.Helpers.Helpers; using Project.Helpers.IO; namespace Project.Site.Areas.MemberToolsReports.Controllers { public class RankingsController : BaseController { #region PROPERTIES [Dependency] public IGeographyService GeographyServiceInstance { get; set; } [Dependency] public IRankingsService RankingsServiceInstance { get; set; } [Dependency] public IUtilityService UtilityServiceInstance { get; set; } #endregion #region ACTIONS public ActionResult Index() { var states = getting states here var key = String.Empty; var search = new RankingSearch { Key = key }; var model = new RankingSearchViewModel { Search = search, StatesList = states }; return View(model); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult Index(RankingSearchViewModel model) { var errorModel = new ContentShowError { IsError = true }; var resultModel = new RankingsSearchResultsViewModel(); try { //TODO: remove extra code once data annotations issue is fixed on staging and prod if (!Request.IsAjaxRequest()) { errorModel.Message = base.GetDisplayMessage(ProcessingMessagesEnum.ErrorServicingRequest); } else if (!TryValidateModel(model) || !ModelState.IsValid) { errorModel.Message = base.GetDisplayMessage(ProcessingMessagesEnum.ErrorProcessingRequest); } else if (String.IsNullOrWhiteSpace(model.Search.Key) && String.IsNullOrWhiteSpace(model.Search.Institution) && String.IsNullOrWhiteSpace(model.Search.State)) { errorModel.Message = base.GetDisplayMessage(ProcessingMessagesEnum.NoCriteriaSpecified); } else { //default - debug code errorModel.Message = base.GetDisplayMessage(ProcessingMessagesEnum.ErrorNoDataFound); var results = RankingsServiceInstance.SearchRanking(model.Search); if (results != null && results.Count > 0) { errorModel.IsError = false; errorModel.Message = String.Empty; //update result model resultModel.Rankings = results; } } } catch (Exception ex) { errorModel.Message = base.GetDisplayMessage(ProcessingMessagesEnum.ErrorProcessingRequest); base.LogException(ex); } ActionResult result = null; result = errorModel.IsError ? PartialView(ViewNames.ErrorControl, errorModel) : PartialView(ViewNames.SearchResultsControl, resultModel); return result; } #endregion } }
Update 2 - HTML Difference
It seems that the validation attributes do not even get into the html, as if the site does not even know that we are using validation. Right now, both dev and intermediate sites have the same code.
Placement
<input autofocus="autofocus" class="clearSearchFields" id="Search_Key" maxlength="6" name="Search.Key" size="6" type="text" value="" /><br />
Developer work site
<input autofocus="autofocus" class="clearSearchFields" data-val="true" data-val-length="Key must be 6 characters long" data-val-length-max="6" data-val-length-min="6" data-val-regex="Only alphanumeric (AZ az 0-9) values are allowed" data-val-regex-pattern="[A-Za-z0-9]*" id="Search_Key" maxlength="6" name="Search.Key" size="6" type="text" value="" /><br /> <span class="field-validation-valid" data-valmsg-for="Search.Key" data-valmsg-replace="true"></span>