나는이 오류와 함께 화를 낼 것입니다. POST 500 내부 서버 오류
POST http://localhost:56105/Home/getContactbyId?ConId=%225%22 500 (Internal Server Error)
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;
}
}
}
는 HTTP 오류를 일으키는 확인하기 위해 서버 응용 프로그램 로그 (응용 프로그램 이벤트 뷰어)를 확인해야합니다. 서버 측 코드에 중단 점을 설정하여 오류가 발생한 위치를 확인하거나 예외를 기록하려고 시도 했습니까? – ADyson
@ADyson이 지적했듯이 서버 측 코드를 디버깅해야합니다. 중단 점을 설정하고 IDE를 연결하십시오. 그럴 수 없다면 로깅을 추가하십시오. – Igor
@DannyFardyJhonstonBermúdez가 위에서 말한대로 ConId 주위에 따옴표가 추가 된 것 같습니다. 디코딩 된 URL - http : // localhost : 56105/Home/getContactbyId? ConId = "5" – KieranDotCo