convalida funziona normalmente su box locale, sito dev ma non sta accadendo nei siti di staging e produzione. La convalida lato client e lato server non sta accadendo. Sia la messa in scena che la produzione sono bilanciate dal carico, ma usano una connessione appiccicosa a causa di altri requisiti funzionali.DataAnnotations - Convalida non valida
Ho controllato la cartella bin su tutti gli ambienti e vedo lì le seguenti due DLL.
DataAnnotationsExtensions.ClientValidation.dll
DataAnnotationsExtensions.dll
Sul lato server, il seguente errore dovrebbe non riuscire.
!TryValidateModel(model) || !ModelState.IsValid
Questo sito utilizza l'autenticazione di Windows.
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>
A scopo di verifica, non sto usando fasci in questo momento. Per i pacchi, ho anche provato con seguente
<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>
E ho i seguenti file JS si fa riferimento pure
<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>
L'applicazione è MVC 5 e tutto è stato aggiunto tramite il pacchetto NuGet. Non ho MVC installato sul server. Ho un'altra app MVC 5 su questi server e la convalida sta andando bene.
E qui è il tag form, la seconda applicazione di lavoro utilizza lo stesso tag form.
using (Html.BeginForm(ActionNames.Index, ControllerNames.Rankings, new { Area = AreaNames.MemberToolsReports }, FormMethod.Post, new { id = "RankingsSearchForm" }))
Sulle vecchie di sosta e di produzione scatole, validazione stava lavorando ma poi abbiamo avuto MVC 3 installato su di esso.
Update - Codice controller
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 - Differenza HTML
Sembra attributi di validazione non sono nemmeno rendere al html, come se il sito non sa nemmeno che stiamo usando la validazione. Al momento, sia i siti di sviluppo che di sviluppo hanno lo stesso codice.
sito di staging
<input autofocus="autofocus" class="clearSearchFields" id="Search_Key" maxlength="6" name="Search.Key" size="6" type="text" value="" /><br />
Lavorare sito dev
<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 (A-Z a-z 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>
è possibile visualizzare il controller – Sachu
eventuali errori nella console? E un'altra domanda sciocca: hai aggiunto jquery alla tua pagina? –
mostra il controller – ediblecode