Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm new to ASP .NET, MVC and AngularJS so I'm trying to figure this all out still.

I have a Model called Words.cs which contains:

namespace liveSearch.Models
{
    public class Words
    {
        public int ID { get; set; }
        public string Word{ get; set; }
    }
}

The database is already populated with data and I want to use JavaScript/JQuery to get every Word from the database and then use AngularJS to display that on my index.cshtml page.

I currently have Razor in my index.cshtml which does:

@{
     foreach (var item in Model)
     {
         <li>
             @Html.DisplayFor(modelItem => item.Word)
         </li>
     }
 }

This works in getting and displaying all Words in the model but I want to get rid of the Razor and use JavaScript/Jquery to get the data and AngularJS to display it there.

Ideally, I want to get all Words from the DB (I don't care about the IDs) and add it to an array in the scope. Then I can use AngularJS to display each Word by using ng-repeat.

The problem is that I don't know how to get all the Words into an array in the scope from the DB/model.

I think I can use $.get() or $.ajax() but I don't really know how to use it with a DB/model.

Thank you

share|improve this question

Angular is a client side technology. .Net is server side. Your .net code will have to be changed to an API that the Angular code will be able to use. I suggest you read up on WebApi to creat a RESTful service that your Angular code can then consume.

share|improve this answer
    
Ok forget about Angular. Can I at least get the DB data using JavaScript/JQuery? – user3636407 23 hours ago
    
JavaScript and jQuery are also client side technologies. They'll still require a RESTful API (or equivalent) from the server side. It's worth the investment to learn it. – Kesty 22 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.