I've been searching for three days and have not seen anything like this anywhere else.
Checking if it was some kind of hosting block, I hosted the site on godaddy, and then on the azure to confirm, and continued the same thing.
Summarizing the problem: Validation on the client side only works on localhost, when I publish the web application, this validation stops working. Only the error message does not appear, the rest works normally.
I use visual studio 2013. I'm using MVC and DataAnnotations as follows in my Patient model:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
using Maoli.Mvc;
namespace ALLIVICI.Models
{
public partial class tbPaciente
{
public tbPaciente()
{
this.tbMedico_Paciente = new List<tbMedico_Paciente>();
}
[Key]
public int IdPaciente { get; set; }
[Required(ErrorMessage = "Esse campo é obrigatório")]
[StringLength(100, ErrorMessage = "Esse campo deve conter no máximo 100 letras")]
[RegularExpression("^([^0-9])*$", ErrorMessage = "Esse campo não deve conter números")]
public string Nome { get; set; }
//[Required(ErrorMessage = "Esse campo é obrigatório")]"^[A-Za-z0-9](([_.-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([.-]?[a-zA-Z0-9]+)*)([.][A-Za-z]{2,4})$"
//public string Email { get; set; }
//[Required(ErrorMessage = "Esse campo é obrigatório")]
[RegularExpression("(^[A-Za-z]{2}[-][0-9]{2}[.][0-9]{3}[.][0-9]{3})$", ErrorMessage = "Por favor, preencha o campo no formato: AA-00.000.000")]
public string RG { get; set; }
[RegularExpression("^[0-9]{11}$", ErrorMessage = "Esse não é um CPF válido")]
[Required(ErrorMessage = "Esse campo é obrigatório")]
[Cpf(ErrorMessage = "Esse CPF não existe! Por favor, informe um CPF válido.")]
public string CPF { get; set; }
//"(^\d{3}.\d{3}.\d{3}-\d{2}$)|(^\[0-9]{11}$)|(^_{3}\._{3}\._{3}-_{2}$)"
[Required(ErrorMessage = "Esse campo é obrigatório")]
[RegularExpression("^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)[0-9][0-9](( )([0-9][0-9][:]){2}[0-9][0-9])?", ErrorMessage = "Por favor, preencha o campo no formato 01/01/2000")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public System.DateTime DataNascimento { get; set; }
public string NomeResponsavel { get; set; }
public string Sexo { get;set; }
public int Etnia { get; set; }
public string Endereco { get; set; }
public string Bairro { get; set; }
[RegularExpression("^[(]{1}[1-9]{2}[)]{1}[0-9]{4}[-]{1}[0-9]{3,4}$", ErrorMessage = "Por favor, preencha o campo no formato: (00)1234-5678")]
public string TelResidencial { get; set; }
[RegularExpression("^[(]{1}[1-9]{2}[)]{1}[0-9]{4}[-]{1}[0-9]{3,4}$", ErrorMessage = "Por favor, preencha o campo no formato: (00)1234-5678")]
public string TelComercial { get; set; }
[RegularExpression("^[(]{1}[1-9]{2}[)]{1}[0-9]{4,5}[-]{1}[0-9]{3,4}$", ErrorMessage = "Por favor, preencha o campo no formato: (00)1234-5678 ou (00)12345-6789")]
public string TelCelular { get; set; }
public string Profissao { get; set; }
public bool FlgAtleta { get; set; }
public bool FlgGestante { get; set; }
public virtual ICollection<tbMedico_Paciente> tbMedico_Paciente { get; set; }
In my _Layout I have the following code including rendering scripts:
@using Microsoft.AspNet.Identity
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
@*<a href="~/Views/Shared/_LoginPartial.cshtml">~/Views/Shared/_LoginPartial.cshtml</a>*@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - ALLIVICI</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
@if (!Request.IsAuthenticated)
{
<center><h2>Em construção</h2></center>
}
@if (Request.IsAuthenticated)
{
if (!HttpContext.Current.Request.Url.AbsolutePath.Equals("/tbProfs/Create"))
{
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("ALLIVICI", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Inicio", "Index", "Home")</li>
<li>@Html.ActionLink("Sobre", "About", "Home")</li>
<li>@Html.ActionLink("Contato", "Contact", "Home")</li>
</ul>
@Html.Partial("_LoginPartial")
</div>
</div>
</div>
}
}
<div class="container">
@if (Request.IsAuthenticated)
{
if (!HttpContext.Current.Request.Url.AbsolutePath.Equals("/tbProfs/Create"))
{
@Html.Partial("_Menu")
}
}
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year</p>
@*<div align="right"></div>*@
</footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>
In my BundleConfig.cs I just added Maoli:
using System.Web;
using System.Web.Optimization;
namespace ALLIVICI
{
public class BundleConfig
{
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
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*",
"~/Scripts/maoli*"
));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
}
}
I have a simple controller:
// POST: tbPaciente/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "Nome,RG,CPF,DataNascimento,NomeResponsavel,Sexo,Etnia,Endereco,Bairro,IdCidade,TelResidencial,TelComercial,TelCelular,Profissao,FlgAtleta,FlgGestante")] tbPaciente tbPaciente, [Bind(Include = "InformacaoResumida")] tbMedico_Paciente tbMP)
{
var idU = User.Identity.GetUserId();
tbMP.IdPaciente = tbPaciente.IdPaciente; //var y = db.tbProfs.Where(x => x.IdUser.Equals(id)); //y e w são iguais.
var w = from c in db.tbProfs
where (c.IdUser == idU)
select c;
tbMP.IdProf = w.Single().IdProf;
//var k = from d in db.tbMedico_Paciente
// where (w.Single().IdProf == d.IdProf)
// where (d.IdPaciente == tbPaciente.IdPaciente)
// select d;
if (ModelState.IsValid)
{
db.tbPacientes.Add(tbPaciente);
db.tbMedico_Paciente.Add(tbMP);
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewBag.IdCidade = new SelectList(db.tbCidades, "IdCidade", "nome", tbPaciente.IdCidade);
return View();
}
And to top it off, my web.config is something to help out:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=archanjo\sqlnovo;Initial Catalog=db_ALL;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
<add name="db_ALLContext" connectionString="Data Source=archanjo\sqlnovo;Initial Catalog=db_ALL;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<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>
<globalization culture="pt-BR" uiCulture="pt-BR" />
<authentication mode="None" />
<compilation debug="true" targetFramework="4.6" />
<httpRuntime targetFramework="4.6" />
<customErrors mode="Off" />
<trust level="Full" />
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=archanjo\sqlnovo;Initial Catalog=db_ALL;Integrated Security=True;MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
When I publish, the bank connection string is automatically changed to the bank on the correct server.
I was already forgetting about the Patient View ...
@using Microsoft.AspNet.Identity
@using System.Web.Mvc.Html;
@model ALLIVICI.Models.tbPaciente
@{
ViewBag.Title = "Create";
}
<h2>Adicionar</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Paciente</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Nome, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Nome, new { htmlAttributes = new { @class = "form-control", @placeholder = "Nome completo" } })
@Html.ValidationMessageFor(model => model.Nome, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.RG, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.RG, new { htmlAttributes = new { @class = "form-control", @placeholder = "ES-11.111.111" } })
@Html.ValidationMessageFor(model => model.RG, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CPF, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@*<script type="text/javascript">$(document).ready(function(){ $("#cpf").mask("99999999999");});</script>*@
@Html.EditorFor(model => model.CPF, new { htmlAttributes = new { @class = "form-control", @placeholder = "11122233300"} })
@*@Html.ValidateFor(model => model.CPF)*@
@Html.ValidationMessageFor(model => model.CPF, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DataNascimento, "Nascimento", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DataNascimento, new { htmlAttributes = new { @class = "form-control", @placeholder = "01/01/1900" } })
@Html.ValidationMessageFor(model => model.DataNascimento, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.NomeResponsavel, "Responsável", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.NomeResponsavel, new { htmlAttributes = new { @class = "form-control", @placeholder = "Se menor de 18 anos" } })
@Html.ValidationMessageFor(model => model.NomeResponsavel, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Sexo, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Sexo, new SelectList(new[]
{
new SelectListItem {Text = "M", Value = "Masculino"},
new SelectListItem {Text = "F", Value = "Feminino"},
}, "Text", "Value"), htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Sexo, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Etnia, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@*@Html.EditorFor(model => model.Etnia, new { htmlAttributes = new { @class = "form-control" } })*@
@Html.DropDownListFor(model => model.Etnia, new SelectList(new[]
{
new SelectListItem {Text = "0", Value = "Branco"},
new SelectListItem {Text = "1", Value = "Índio"},
new SelectListItem {Text = "2", Value = "Negro"},
new SelectListItem {Text = "3", Value = "Oriental"},
new SelectListItem {Text = "4", Value = "Pardo"},
}, "Text", "Value"), htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Etnia, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Endereco, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Endereco, new { htmlAttributes = new { @class = "form-control", @placeholder = "Rua, número, logradouro" } })
@Html.ValidationMessageFor(model => model.Endereco, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Bairro, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Bairro, new { htmlAttributes = new { @class = "form-control", @placeholder = "Bairro" } })
@Html.ValidationMessageFor(model => model.Bairro, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.IdCidade, "Cidade", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("IdCidade", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.IdCidade, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TelResidencial, "Tel. Residencial", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TelResidencial, new { htmlAttributes = new { @class = "form-control", @placeholder = "(00)1234-5678" } })
@Html.ValidationMessageFor(model => model.TelResidencial, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TelComercial, "Tel. Comercial", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TelComercial, new { htmlAttributes = new { @class = "form-control", @placeholder = "(00)1234-5678" } })
@Html.ValidationMessageFor(model => model.TelComercial, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TelCelular, "Celular", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TelCelular, new { htmlAttributes = new { @class = "form-control", @placeholder = "(00)1234-5678 ou (00)12345-6789" } })
@Html.ValidationMessageFor(model => model.TelCelular, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Profissao, "Profissão", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Profissao, new { htmlAttributes = new { @class = "form-control", @placeholder = "Ocupação principal" } })
@Html.ValidationMessageFor(model => model.Profissao, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FlgAtleta, "Atleta", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<div class="checkbox">
@Html.CheckBoxFor(model => model.FlgAtleta)
@Html.ValidationMessageFor(model => model.FlgAtleta, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FlgGestante, "Gestante", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<div class="checkbox">
@Html.CheckBoxFor(model => model.FlgGestante)
@Html.ValidationMessageFor(model => model.FlgGestante, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.tbMedico_Paciente.Where(x => x.tbProf.IdUser.Equals(User.Identity.GetUserId())).Single().InformacaoResumida, "Informação Extra", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.tbMedico_Paciente.Where(x => x.tbProf.IdUser.Equals(User.Identity.GetUserId())).Single().InformacaoResumida, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.tbMedico_Paciente.Where(x => x.tbProf.IdUser.Equals(User.Identity.GetUserId())).Single().InformacaoResumida, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Salvar" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Voltar para lista de pacientes", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
Any additional information that someone needs to help me is just asking.
Any help, any help, will be welcome. Thank you.
EDIT: Guys, thank you very much to everyone. I made a minimal example according to Sérgio and with the brasophile and ... it worked. I then took a 0.1 version from two weeks ago, when I had not yet hosted it, and it also worked ... So I was gradually adding in version 0.1 what I had done in those two weeks to find out what was wrong. To my surprise, I finished adding everything and the error did not occur. To be sure, in the end, I copied all the models, controllers and views of the other to version 0.1 and even then it worked normally. Until I realized that the only difference left was the translation packages en and the Maoli of manage NuGet that one had and the other did not. The problem was right there, I uninstalled all these from the old one and it also worked. Now, I am adding the packages one by one in a test version and see what caused the error in my program, or even if it was the interaction between one and the other. Thanks everyone, finding out, post here.
EDIT2: Guys, you can close the question. It seems that it was some conflict with the Maoli package, although I do not know exactly what. Thank you all.