I created a View based on a strongly typed model class in my MVC4 project and it all worked well. However I had to add a bunch of fields to the Model class and now I want the View to reflect that. Originally all the fields were created automatically for me when I selected the strogly typed class.
I know I could manually go and add the new HTML helper fields, but I was wondering if there was some way to ‘Update’ the View from it’s bound model class (i.e. some link in the IDE like “Refresh View” or something”).
I also know I could delete the current View and have it re-created but I was wondering if it was possible with a bit less brute force in case I had made unrelated customizations that I didn’t want wiped out.
Thanks!
If you use EditorForModel() or DisplayForModel() in your view, they will update for free when you make changes to your model.
Here’s the link to Brad Wilson’s blog post that I’ve found super useful. It’s written for MVC2, but as far as I know, everything still applies in MVC3.
Also, a particular data annotation that is really handy when using EditorForModel() is: