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.
The File Structure
This is how we are going to structure our project.
Creating ASP.NET MVC BACK END
- Create the Contact.cs POCO
Create this file under the Models folder. This will be use to store contact information.
- Install the EntityFramework
Using Manage NuGet Package, install the EntityFramework.
- Create the ContactContext.cs
Create this file under Models folder.
- 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. - 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
ReplyError 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?)
means my ContactContext is Empty, what should i do.
Replyi m new to this world and learning.
if you can teach how to multi national address controller it will be really helpfull
Excelente artigo para nós programadores iniciantes, parabéns.
ReplyGreat Article
ReplyMVC 5 Training
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.
ReplyHi Salman Welji,
ReplyYou 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.
I'm on this part either and I get this error:
Reply'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; } ?
nice blog,
Replyregards
Angular 5 training!
Angular 5 training in hyderabad!
best Angular 5 training institutes!
GOOD POST
Replyhttp://spunksoft.com/course/rpa-training-in-hyderabad/
•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.
ReplyFor more details: AngularJs training in velachery
Thanks for sharing this informative blog.
ReplyBudget family rooms in Ooty