开发者

mvc and jquery - does the model get left out? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the he开发者_StackOverflowlp center for guidance. Closed 11 years ago.

I am building an asp.net mvc 3 web application. I am also a jquery fan. I am not sure how to go about the design, as currently I can see two options:

  1. Use the controller as something similar to a web service. Encapsulate the method calls relevant for each page, and use jquery to perform ajax calls to the web page. Then, use jquery tempting to populate the page based on the server's response.

  2. Just use the model in my view. Avoid any jquery ajax calls that have to do with populating page's content.

I guess that there's no right or wrong here, but I'd really like to hear the pros and cons of the two options from experienced developers.

Thank you


it depends upon situation to situation. look at stackoverflow for instance. it is built in asp.net mvc AFAIK. it serves major content in traditional way whereas adding comments, showing them simultaneously, tag selection is done using ajax calls. we have been using same approach: serve major content(questions and answers on stackoverflow) in traditional way and do minor tweaking with ajax and jquery


I think it's largely dependent on the model size and personal preference. If you have a large model, you'd almost certainly want to use AJAX so you don't delay the page from opening.

It's easy to populate a dom object with some data from the model. It's a little more difficult using that data within javascript though. You either have to use things like hidden inputs, or write a html helper that serializes your model into javascript and loads it into a javascript object. The downside to this approach is that your model data is clearly visible to anyone who looks at the code behind and it makes your page size larger.

I've been using approach number one personally.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜