开发者

asp.net mvc save postback object tree to database and retrieve it. (implement save button)

For background reference: The application is built in asp.net mvc 3, the backend is built with the help of entity framework and services and for the front end I copy the domain objects to DTO objects. The DTO objects have the validation attributes on them.

The customer that works in this 开发者_StackOverflowapplication needs to fill in some rather big forms. After it is filled it it will be submitted to someone else who has to evaluate the information. So after the submit the status becomes pending until validated.

But when the customer is called away I would like the customer to have the ability to save away its form without submitting it or loosing information. I realize I need to do 2 things to accomplish this. 1 is to disable the javascript validation on the save button. I think that wouldn't be that hard. Then step 2 store the form state (dto and some object that represents the validation result) to the database. And then when the form is opened afterwards those values need to be recovered. What I want to accomplish is a delayed serverside validation.

So the process will be:

Fill in form -> Push save -> disable js validation -> post object to server -> store dto + validation in database -> ...... -> load data from database and attach to form?? -> post back to the client.....

Conceptually I think this could be a way to do it. (Please tell me if you have an other idea or disagree with me).

Does anyone has a clue how to build it. Especially the save and load of the data from the database. What would I need to persist? Can I reattach it back to the contexts etc... One extra note, I don't use cookies/session variables etc etc.


The answer to this depends on the validation mechanism on your DTO's but if you can add invalid data to the DTO you can then serialize the DTO's object graph as whatever (Binary, DataContract, XML, Json, etc.) Once serialized you could store the object graph in the database and the next time the user logs in you can deserialize the data back into the DTO's to present to the view. I would take a look at the different serializers (DataContractSerializer is in System.Runtime.Serialization and serializes to XML) to see which fits your needs best.

        MemoryStream ms = new MemoryStream();
        System.Runtime.Serialization.DataContractSerializer serializer = new System.Runtime.Serialization.DataContractSerializer(typeof(ViewModel));
        serializer.WriteObject(ms, vmInstance);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜