My ApplicationController
:
public class ApplicationController : Controller
{
private IUxRepository _repository;
public ApplicationController(IUxRepository repository)
{
_repository = repository;
}
public ActionResult Create()
{
return View("Shape", new ApplicationViewModel());
}
}
My ApplicationViewModel
public class ApplicationViewModel : ViewModelBase
{
public ApplicationViewModel()
{
Application = new Application();
}
public Application Application {get;set;}
}
My Application
Model:
public class Application : DbEntity
{
public string Name {get;set;}
[Display(Name = "Proposed Release Date"),
RegularExpression(@"(^Q[1-4])\s(2\d{3})", ErrorMessage = "Date needs to be in the format Q{1-4}{space}20{YY} e.g. Q4 2013 or Q1 2014")]
public string ProposedReleaseDate {get;set;}
}
Extract from Shape
view:
<div class="editor-label">
@Html.DisplayFor(model => model.ProposedReleaseDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ProposedReleaseDate)
@Html.ValidationMessageFor(model => model.ProposedReleaseDate)
</div>
When I try and load up my Shape
view, for some reason it comes back with a validation error saying the ProposedReleaseDate
doesn't meet the required RegularExpression
.
Of course it doesn't because it's a new entity waiting for the input, why is it validating before the page has loaded up. Its validating too early. How do I bypass this, or where do I turn this feature off, its counter intuitive/productive IMHO.