Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Cort Larsen 388 posts 922 karma points
    Sep 29, 2017 @ 15:33
    Peter Cort Larsen
    0

    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; } }

    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) {});
    
    
    
        }
    }
    

    });

    View

    <form novalidate ng-submit="send()" name="loginForm" ng-controller="LoginCtrl">
                <fieldset>
                    <div class="row">
                        <div class="col-s-6">
                            <label for="txtName">@Umbraco.Field("#Customer_name", altFieldAlias: "Customer ID"):</label>
                            <input ng-model="txtCustomerID" type="text" id="txtCustomerID" value="" required placeholder="@Umbraco.Field(" #Customer_name", altFieldAlias "Customer ID" )">
                            <label for="txtName">@Umbraco.Field("#Password", altFieldAlias: "Password"):</label>
                            <input ng-model="Password" type="password" id="txtPassword" value="" required placeholder="@Umbraco.Field(" #Password", altFieldAlias "Password" )">
                        </div>
                    </div>
                </fieldset>
                <div class="form-actions">
                    <input type="submit" class="btn" value="@Umbraco.Field(" #Login", altFieldAlias "Login" )" />
    
                </div>
            </form>
    
  • Peter Cort Larsen 388 posts 922 karma points
    Sep 29, 2017 @ 15:38
    Peter Cort Larsen
    0

    its like the form isnt submitting at all.

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Sep 29, 2017 @ 16:29
    Alex Skrypnyk
    0

    Hi Peter

    Can you check that angular works fine on your page?

    Some other angular logic is working fine?

    Thanks,

    Alex

  • Peter Cort Larsen 388 posts 922 karma points
    Sep 29, 2017 @ 16:53
    Peter Cort Larsen
    0

    Hi,

    A simple check :

    i added this after the body tag

    {{3 + 3}}

    and it returns : 6

    so its working fine.

  • TheCodeMan 7 posts 97 karma points
    Oct 01, 2017 @ 12:31
    TheCodeMan
    100

    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

  • Peter Cort Larsen 388 posts 922 karma points
    Oct 02, 2017 @ 15:31
    Peter Cort Larsen
    0

    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.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies