I am passing url from view to controller for $http.Post.
View(Asp.net MVC View)
<form name="form" ng-controller="LoginController" >
<div id="dvContainer" ng-init="Url= @Url.Action("VerifyLogin", "Visitor")">
<span ng-model="Message" class="text-danger"></span>
<table>
<tr>
<td>UserName</td>
<td>
<input name="txtUser" type="text" required ng-model="UserName" />
<span ng-show="(form.txtUser.$dirty || submitted) &&
form.txtUser.$error.required">UserName is required.</span>
</td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" required ng-model="Password" /></td>
</tr>
<tr>
<td colspan="2"><button type="submit" ng-click="submit($event)">Login</button></td>
</tr>
</table>
</div>
</form>
In my Controller(Angularjs Controller)
var app = angular.module('VisitorApp', []);
//AngularJS controller
app.controller('LoginController', function ($scope, $http) {
$scope.submit = function () {
alert('hi')
// Set the 'submitted' flag to true
alert($scope.UserName);
alert($scope.Password);
var loginModel = {
UserName: $scope.UserName,
PassWord:$scope.Password
};
$http.post($scope.Url, loginModel).success(function (data) {
$scope.Message = data.Message;
}).error(function (data) {
$scope.error = "An error has occured while adding! " + data;
});
};
});
I am trying to access Url that is being defined using ng-init . The application is throwing error
[$parse:syntax] Syntax Error: Token '/' not a primary expression at column 6 of the expression [Url= /Visitor/VerifyLogin] starting at [/Visitor/VerifyLogin].
I am pretty new to Angularjs so Could not figure out what is that i am doing wrong.
$scope.Urlget defined?