Now, open HomeController. By default, HomeController will be inheritted by Controller as HomeController:Controller. Change it to HomeController:ApiController and copy the code, given below.
using AngularwithWebAPI.DbContext;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http; //This namespace is responsible for IHttpActionResult
using System.Web.Mvc;
namespace AngularwithWebAPI.Controllers
{
publicclassHomeController: ApiController {
DbContext.StudentEntities studentEntities = new DbContext.StudentEntities();
publicIHttpActionResult GetStates() {
var states = studentEntities.StateMasters.ToList();
return Ok(states);
}
}
Now run your Service
Script.js
var testApp = angular.module("testModule", []).controller("testController", function($scope, $http) {
Bidyasagar MishraRank #766 · 3K reputationPosted Aug 24, 2019, 1:15 AM EDT
Chittaranjan SwainRank #216 · 11.3K reputationPosted Aug 24, 2019, 12:45 AM EDT
Chittaranjan SwainRank #216 · 11.3K reputationPosted Aug 24, 2019, 12:40 AM EDT
AngularJs Select Box or Dropdown List example
AngularJS Select Box or Dropdown List Example
Chandrasekaran C134 reputationPosted Aug 24, 2019, 12:42 AM EDT