Creating CRUD Application with ASP.NET MVC 5, AngularJS, BootStrap 3, and HTML5 - Part 3

Part 3 : Creating the Back End Using ASP.NET MVC

The are 2 ways we can pass data to and from ASP.NET MVC to Angular:
1. By BootStrapping = Using cshtml
2. By Angular $http Service = In this tutorial, we will use this.

NOTE: We are not going to use Web Api. We will use the Controller to communicate with the AngularJS.

The File Structure
This is how we are going to structure our project.



Creating ASP.NET MVC BACK END
  1. Create the Contact.cs POCO
    Create this file under the Models folder. This will be use to store contact information.
  2. Install the EntityFramework
    Using Manage NuGet Package, install the EntityFramework.
  3. Create the ContactContext.cs
    Create this file under Models folder. 
  4. Create Json Camelcase Resolver to convert JSON to Camelcase format.
    The AngularJS uses camelcase so we need to a Json converter to convert Pascal case (from C#) to camelcase.
    Create a Helper folder (as shown in the file structure above) and add a controller named JsonController.cs.
  5. Create the ContactController.cs
    This is where we will be having data exchange with AngularJS.
    Under the Controllers folder. Right click on it and add empty controller. Name it as ContactController. Notice that this controller inherits from the JsonController which is the Json camelcase resolver.


Part 4 : Communicating with ASP.NET MVC

12 comments

i m on part 3 and getting error it says
Error 1 'AngularJSApp.Models.ContactContext' does not contain a definition for 'Contact' and no extension method 'Contact' accepting a first argument of type 'AngularJSApp.Models.ContactContext' could be found (are you missing a using directive or an assembly reference?)

Reply

means my ContactContext is Empty, what should i do.

i m new to this world and learning.

if you can teach how to multi national address controller it will be really helpfull

Reply

Excelente artigo para nós programadores iniciantes, parabéns.

Reply

Hey, Nice update. I have a little bit idea about Asp.net MVC when I hosted my website on Myasp.net. But after reading this blog, I get something about CRUD application and How it creates by using Asp.net application. Thanks for sharing and keep blogging new updates like this.

Reply

Hi Salman Welji,

You have to put below in to ContactContext page and your error has been solved.


public class ContactContext : DbContext
{
public DbSet Contacts { get; set; }

}

Thanks

Its great article.

Reply
This comment has been removed by the author.

I'm on this part either and I get this error:

'ContactContext' does not contain a definition for 'Contacts' and no extension method 'Contacts' accepting a first argument of type 'ContactContext' could be found (are you missing a using directive or an assembly reference?)

I just need to go to ContactContext.cs and add
public object Contacts { get; set; } ?

Reply

GOOD POST
http://spunksoft.com/course/rpa-training-in-hyderabad/

Reply

•Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.We are providing AngularJS training in Velachery.

For more details: AngularJs training in velachery

Reply

Thanks for sharing this informative blog.
Budget family rooms in Ooty

Reply