开发者

Asp.net mvc models without databases/framework

Are there any tutorials/examples on how to create an asp.net mvc app without the model being managed by a database (through linq2sql or entity framework). I've to create a frontend for a server which has a json based api. I would like to use mvc 3 or 2 and have most of the features of mvc still in place (like data annotation and validation). Any tutorials or examples on how to do this? I 开发者_StackOverflowtried to search them but all examples i find are based on entity framework or linq.


I agree that most of the examples/tutorials out there are using entity framework. This being said the process would be similar:

  1. Create your model classes.
  2. Create a repository working with those model classes. This repository should implement an interface which contains all the operations you need with those models like GetUser, SaveUser, etc... In the implementation you connect to the remote JSON API server to fetch data.
  3. You create a controller which takes the repository interface in the constructor. Setup a custom controller factory so that a DI framework could provide instances of your controllers.
  4. Define views and view model classes.
  5. Controller actions talk to the repository via the provided interface to fetch models, maps those models to view models and returns them to the corresponding view to be shown.

Useful tools:

  • MvcContrib (many useful helpers)
  • AutoMapper (for mapping between models and view models)
  • FluentValidation.NET (for validating models)


MVC 3 has extra support for JSON which you might want to look into.

Or use the futures with MVC 2.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜