Я попытался кучу вещей, и это то, что я до сих пор:Угловая asp.net MVC вызова с функцией # контроллер
Так я пытаюсь вызвать этот метод «RunTest()» из моего JavaScript. Метод на самом деле не идет, и он проходит успешно, поэтому «handleTest()» идет, а также преуспевает. Мне нужно, чтобы он фактически вызывал функцию контроллера.
JavaScript/Угловая/JQuery
$scope.runTest = function (myTest) {
$.ajax({
method: 'POST',
Url: 'Tests/runTest',
contentType: 'application/json;',
data: myTest,
success: function() { handleTest(myTest); },
error: function() { alert('no object found'); }
});
}
function handleTest(currentTest){
var updated = { id: currentTest.id, name: currentTest.name, schedule: currentTest.schedule, description: currentTest.description, server: currentTest.server, port: currentTest.port, method: currentTest.method };
//var updated = currentTest;
$http({
method: "PUT",
url: 'http://~~api address~~/api/tests/' + (currentTest.id),
data: updated
})
.success(function (data, status, headers) {
alert("Test was successfully updated.");
$state.reload();
})
.error(function (data, status, headers) {
alert("Test could not be updated.");
$state.reload();
});
}
C# метод контроллера (названный TestsController)
[HttpPost]
public ActionResult runTest(StandardTest myTest)
{
myTest.lastResult = MyEnum.Pass;
log.Info(myTest.name + " " + myTest.lastResult + " " + myTest.id);
return Json(myTest, JsonRequestBehavior.AllowGet);
}
Любая помощь будет так так оценили.
Что вы добавили, не удалось полностью исправить мою проблему, но это поставило меня на правильный путь, и я получил его на работу, спасибо !!! –