开发者

ASP.NET MVC AJAX Database update - ViewModel vs Controller

I've currently got a controller which passes a model to a view. The view will be making AJAX calls to the controller to make updates to the data rather freqeuently, and the model makes for a rather nice arrangements to make these updates.

I know that making changes to the database in the controller is bad form, and I would like to avoid doing it. However, creating a model on every call and handing the update data off to it, although it seems more correct to me, takes longer on each request, as the model needs to be initialized. Since the user is blocked from interaction with certain elements on the page during the update, this time can really add up across dozens 开发者_Go百科of updates.

Which method is best? Simply making the updates in the controller to keep the application as interactive as possible, or initializing an instance of the model on every request to handle the update at the expense of speedy request processing?


I would suggest optimize your model and/or create a lighter version of it.

Why is your model taking too long to initialize? Is the initialization loading things that you don't need when called in this particular case?

Bottom line, I would move the saving logic to a model but would make sure the model is fast and optimal.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜