Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 tried to search them but all examples i find are based on entity framework or linq.

like image 467
Toad Avatar asked May 02 '26 10:05

Toad


1 Answers

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)
like image 111
Darin Dimitrov Avatar answered May 03 '26 23:05

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!