MVC Partial Model Updates -
I often find myself in a situation where I just want to present and edit some fields from my model I have a model that represts an address, maybe I just want the form updating the city and post code fields (bad examples, but hopefully this scenario explains)
I have two methods Out of the know:
1) Unwanted fields hidden in these Put it on the form in put elements, or ... 2) Create a dedicated visualization model that only defines the required field.
I # 2, but the action of my controller is not a good way to merge data from the model to look back in the 'real' model. At the moment, I follow this approach ...
1) I record the record in a hidden area on the visual model 2) When the page is posted back, the controller retrieves the original record and i manually view each model for the actual model Model s Give each field 3) Save to the data store to the actual model.
It works, but is it quite a work and an assignment / rescheduling and I was wondering if anyone had an idea of another?
After
.
Something like this:
Public class BaseClassOfProperties {public string name {get; Set; }} Public Interface INameViewableProperties {[Display (name = "Your name")] String name {get; Set; }} Public Interface INameHiddenProperties {// [scaffoldColumn] This completely hides the area [UIHint ("hidden")] / I think ... string name {get; Set; }} [MetadataType (typeof (INameViewableProperties)] Public Square NameViewAbleProperties: BaseClassOfProperties {} [MetadataType (typeof (INameHiddenProperties)] Public class NameHiddenProperties: BaseClassOfProperties {}
Comments
Post a Comment