J. Petersen J. Petersen -4 years ago 120
AngularJS Question

Trouble it gives me 404 (not found) - After I click on my submit

This is how I have set up my whole hand to show off content as it should. but when I eg. click submit you will see it with this error

http://localhost:57298/Opgaver/FindTask/3/Jesper Failed to load resource: the server responded with a status of 404 (Not Found)

My json is in the correct folder as it should, etc.. Error occurs only when I click submit content

I have not written anything up in my RouteConfig.cs file on how it should be in relation to the file and angularjs.


var app = angular.module('Opgaver', []);
app.controller('OpgaverCheck', function ($scope, $http) {

//Must make it here when I click submit.
$scope.CheckValue = function (module) {
//console.log("Hello world " + module.Id + " - " + module.text);

$scope.$watch("module.Id", function() {
var url = "/Opgaver/FindTask/" + module.Id + "/" + module.text;

$http.get(url).success(function (response) {
//It must give a response back from json it is succe or error.
$scope.jsonMessage = response;

When I run my console.log then it's that I want to do.


public JsonResult FindTask(int Id, string Text)
var db = Helpers.HelperToTables.DbValue;
var valuetext = Text.ToLower();

var check = db.LektionerOpgaves.FirstOrDefault(i => i.fk_LektionerId == Id && i.CorrectAnswer.Equals(valuetext));
if (check != null)
return Json("Succes");
return Json("Error");

Answer Source

From what I can see the correct URI for your route (if you didn't modify the default routing inside RouteConfig.cs) is the following one:


That's because the Text parameter is not mapped to anything inside the route, and thus it will be mapped as a query string parameter.

If you need to map it inside the route you should create a custom route for your specific mapping, you will find more inside the official documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download