2
I researched pacas here and did not find a solution for what I wanted. I wonder if anyone has done something similar in MVC4.
Model:
public class Trabalhador
{
[Required(ErrorMessage = "*")]
public int Id { get; set; }
[Required(ErrorMessage = "*")]
public String Nome { get; set; }
public String Aposentado { get; set; }
[Requerido caso o Aposentado seja "S"]
public DateTime DataAposentadoria { get; set; }
}
View:
@Html.TextBoxFor(model => model.Id)
@Html.ValidationMessageFor(model => model.Id)
@Html.TextBoxFor(model => model.Nome)
@Html.ValidationMessageFor(model => model.Nome)
@Html.TextBoxFor(model => model.Aposentado)
@Html.ValidationMessageFor(model => model.Aposentado)
@Html.TextBoxFor(model => model.DataAposentadoria)
@Html.ValidationMessageFor(model => model.DataAposentadoria)
Here is the X of Questao, I in my form desire all fields, however I want to force me to type the Retirement Date only in the case of a specific value in the Retired attribute (which in case would be "S" or any other value I want). I searched several posts right here in Stack, but none of the models worked.
https://stackoverflow.com/questions/3713281/attribute-dependent-on-another-field/5079585#5079585 http://miroprocessordev.blogspot.com.br/2012/08/aspnet-mvc-conditional-validation-using.html https://stackoverflow.com/questions/2417113/asp-net-mvc-conditional-validation http://blogs.msdn.com/b/simonince/archive/2010/06/04/conditional-validation-in-mvc.aspx
Maybe the attribute
RequiredIf
present in this SOEN reply help you: http://stackoverflow.com/a/15975880/195417– Miguel Angelo
Already put the solution for you.
– Tiedt Tech