0

Using a 'create' scaffold template, I have a form where I want to validate the fields using unobtrusive javascript. I have the usual code as follows:

@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title, "Please enter a title")

Normally all I would have to do to make the validation work is to put the [Required] attribute in the model before each appropriate field. Now the problem is that these models were created automatically from an entity model and they all have comments which say something like:

// This code was generated from a template. 
// Manual changes to this file will be overwritten if the code is regenerated.

I could manually add in these attributes to those classes but then they may get overwritten later if I make any schema changes. So what is the solution?

IanS
  • 315
  • 3
  • 12

0 Answers0