Ich bin verrückt mit diesem Fehler.POST 500 Interner Server Fehler
POST http://localhost:56105/Home/getContactbyId?ConId=%225%22 500 (Internal Server Error)
Hoffe, dass Sie der Lage sein, mir zu helfen. Ich muss Kontaktdaten basierend auf ContactId erhalten. Im Anschluss wird der entsprechende Code (Entschuldigung, wenn ich etwas verpasst, ich werde wenn nötig):
contactController.js
ContactsApp.controller("contactController", function ($scope, $rootScope, $routeParams, $location, myService) {
function getContactById(id) {
var getting = myService.get_Contact_By_Id(id);
getting.then(function successCallback(response) {
$rootScope.Name = response.data.Name;
}, function errorCallback(response) {
return "Error";
});
}
function init() {
var contactId = $location.path().split("/")[2];
console.log(contactId); //this loggs the correct Id
getContactById(contactId);
}
init();
}
myService.js
ContactsApp.service("myService", function ($http) {
this.get_Contact_By_Id = function (ConId) {
console.log(ConId); //this logs the correct id
return $http({
method: 'post',
url: '/Home/getContactById',
params: {
ConId: JSON.stringify(ConId)
}
});
}
}
HomeController.cs
public class HomeController : Controller
{
public string getContactById(int ConId)
{
int id_int = Convert.ToInt32(ConId);
using (ContactsDBEntities contactsData = new ContactsDBEntities())
{
var theOne = contactsData.Contacts.Where(x => x.Id == id_int).FirstOrDefault();
return theOne.Name;
}
}
}
Ein Status von 500 bedeutet einen Fehler auf der Server-Seite zu sehen. Haben Sie auf dem serverseitigen Code Haltepunkte gesetzt, um zu sehen, wo er bricht, oder versucht, Ihre Ausnahmen zu protokollieren? – ADyson
Wie @ADyson darauf hingewiesen hat, müssen Sie Ihren serverseitigen Code debuggen. Legen Sie Haltepunkte fest und hängen Sie Ihre IDE an. Wenn Sie das nicht können, fügen Sie etwas Protokollierung hinzu. – Igor
Scheint, dass Zitate um Ihre ConId hinzugefügt werden, wie @DannyFardyJonstonBermúdez oben sagt ... Dekodierte URL - http: // localhost: 56105/Home/getContactbyId? ConId = "5" – KieranDotCo