My controller never gets reached. I am new at MVC so i need a little help.
I have created a Controller under : App_Code > Controllers. Its called ''LoginApiController''
I have a angular script, thas calls the Controller
I have a Partial View for the html.
But i never reach the controller.
Controller
using System.Linq;
using System.Net.Mail;
using System.Web;
using System.Web.Mvc;
using Umbraco.Web.WebApi;
namespace MyNameSpace
{
public class LoginApiController : UmbracoApiController
{
[HttpPost]
public bool Send(LoginFormModel model)
{
var CustomerID = model.CustomerID;
var Password = model.Password;
return true;
}
}
public class LoginFormModel
{
public string CustomerID { get; set; }
public string Password { get; set; }
}
}
Angular
app.controller("LoginCtrl", function ($scope, $http) {
$scope.CustomerID = '';
$scope.Password = '';
$scope.send = function () {
if ($scope.loginForm.$valid) {
var data = { CustomerID: $scope.CustomerID, Password: $scope.Password };
$http({ method: 'POST', url: '/umbraco/api/LoginApi/Send/', data: data }).success(function (data) {});
}
}
In your angular code try to write to the console example console.log("If i hit F12 in the browser i can see this if I am in the $scope send function.")
Set the console.log under $scope.Password and under $scope.send = function () { and under if ($scope.loginForm.$valid) {... And finally in your .success function.
UmbracoApiController: beginner help
My controller never gets reached. I am new at MVC so i need a little help.
I have created a Controller under : App_Code > Controllers. Its called ''LoginApiController''
I have a angular script, thas calls the Controller
I have a Partial View for the html.
But i never reach the controller.
Controller
using System.Linq; using System.Net.Mail; using System.Web; using System.Web.Mvc; using Umbraco.Web.WebApi;
namespace MyNameSpace {
public class LoginApiController : UmbracoApiController { [HttpPost] public bool Send(LoginFormModel model) { var CustomerID = model.CustomerID; var Password = model.Password; return true; } }
}
Angular
});
View
its like the form isnt submitting at all.
Hi Peter
Can you check that angular works fine on your page?
Some other angular logic is working fine?
Thanks,
Alex
Hi,
A simple check :
i added this after the body tag
{{3 + 3}}
and it returns : 6
so its working fine.
Hello Peter
Just wanted to comment on your code.
You can try to set up at route in your controller like this example http://www.jondjones.com/learn-umbraco-cms/umbraco-developers-guide/umbraco-web-api/how-to-create-a-web-api-in-umbraco-in-less-than-5-minutes
In your angular code try to write to the console example console.log("If i hit F12 in the browser i can see this if I am in the $scope send function.")
Set the console.log under $scope.Password and under $scope.send = function () { and under if ($scope.loginForm.$valid) {... And finally in your .success function.
Hope it helps
Best regards Jakob
Hi,
Thanks for your answers.
After returning a value inside the success function, i could see that everything was working.
So the console.log in the proper place, did the trick.
is working on a reply...