3

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.

2 Answers 2

2

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:

Sign up to request clarification or add additional context in comments.

4 Comments

I can follow you except for step 3. Would your suggested method also support validation to work (via data annotations on the model?)
@Toad, I prefer FluentValidation.NET for validation. I don't use DataAnnotations.
Does this also support client validation?
Yes, currently it has limited support for simple rules like NotNull and Length. Custom validation functions are not supported.
0

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

Or use the futures with MVC 2.

1 Comment

if i read the blogpost correctly, it handles the case where json is posted from the frontend to the webserver. However i'm interested in the part after this... If the webserver wants to store this data using some 3rd part api instead of entityfw or via linq2sql. How does one go about it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.