I'm new to Asp.net combined with Javascript and I can't figure out what to put inside 'url' to get the data from my controller (from entity framework database I created). I keep getting the Error alert because getting data doesn't succeed.
My controller (Controllers/Api/QuestionsController)
namespace Pasapalabra.Controllers.Api
{
public class QuestionsController : ApiController
{
private PasapalabraContext db = new PasapalabraContext();
// GET: api/Questions
public IList<Question> GetQuestions()
{
var questions = db.Questions.ToList();
return questions;
}
// GET: api/Questions/5
[ResponseType(typeof(Question))]
public IHttpActionResult GetQuestionById(int id)
{
Question question = db.Questions.Find(id);
if (question == null)
{
return NotFound();
}
return Ok(question);
}
}
}
My View (Views/Questions/Index.cshtml)
function keepPlaying() {
var questions = getQuestions();
if (questions.length !== 0) {
getRandomQuestion('A');
} else {
gameOver();
}
}
function getQuestions() {
$.ajax({
url: '/api/Questions/',
type: 'GET',
dataType: 'json',
success: function (data) {
return data;
},
error: function (error) {
alert("Error");
}
});
}