I'm trying to read query parameters in my angular controller so I set up the route config confirmedemailcontroller.js
我正在尝试在我的角度控制器中读取查询参数,因此我设置了路由配置confirmmedemailcontroller.js
var app = angular.module('confirmedemail', ['ngRoute']);
app.config(function ($routeProvider, $locationProvider) {
// calls
$routeProvider.when('/confirmedemail/:userid/:token', {
templateUrl: 'templates/confirmedview.html',
controller: 'ConfirmedEmailController'
});
$locationProvider.html5Mode(true);
});
app.controller('ConfirmedEmailController', function ($scope, $http, $routeParams, $location) {
// never calls
// read params from $routeParams and send them then display the result...
//...
});
ConfirmedEmail.cshtml
@{
ViewBag.Title = "Confirm Email";
}
<h2>@ViewBag.Title.</h2>
<div data-ng-app="confirmedemail">
<p>
Thank you for confirming your email. Please @Html.ActionLink("Click here to Log in", "Login", "Home", routeValues: null, htmlAttributes: new { id = "loginLink" })
</p>
<div ng-view></div>
</div>
my root is http://localhost:25715/confirmedemail/111/222, where 111 is userId and 222 is token which I want to read out inside controller
我的root是http:// localhost:25715 / confirmedemail / 111/222,其中111是userId,222是我想在控制器内读出的令牌
But controller never calls. What have I missed?
但控制器从不打电话。我错过了什么?
Updated I have HomeController with working action
更新了我的HomeController与工作行动
public ActionResult ConfirmedEmail(string userId = "", string code = "")
{
ViewBag.Message = "Account confirmed";
return View();
}
and in templates folder there's confirmedview.html
在模板文件夹中有确认视图
1 个解决方案
#1
0
In RouteConfig.cs
routes.MapRoute(
name: "Confirm",
url: "ConfirmedEmail/{userId}/{code}",
defaults: new { controller = "Home", action = "ConfirmedEmail", userId = "", code = "" }
);
in confirmedemailcontroller.js
var app = angular.module('confirmedemail', ['ngRoute']);
app.config(function ($routeProvider, $locationProvider) {
$routeProvider.when('/ConfirmedEmail/:param1/:param2', {
templateUrl: '/templates/confirmedview.html',
controller: 'ConfirmedEmailController'
});
$locationProvider.html5Mode({ requireBase: false, enabled: true });
});
app.controller('ConfirmedEmailController', function ($scope, $http, $routeParams) { ... });
And don't forget about case sensivity! If I call it like mysite.com/confirmedemail/111/222, it won't work
不要忘记案件的敏感性!如果我把它称为mysite.com/confirmedemail/111/222,它将无法正常工作
#1
0
In RouteConfig.cs
routes.MapRoute(
name: "Confirm",
url: "ConfirmedEmail/{userId}/{code}",
defaults: new { controller = "Home", action = "ConfirmedEmail", userId = "", code = "" }
);
in confirmedemailcontroller.js
var app = angular.module('confirmedemail', ['ngRoute']);
app.config(function ($routeProvider, $locationProvider) {
$routeProvider.when('/ConfirmedEmail/:param1/:param2', {
templateUrl: '/templates/confirmedview.html',
controller: 'ConfirmedEmailController'
});
$locationProvider.html5Mode({ requireBase: false, enabled: true });
});
app.controller('ConfirmedEmailController', function ($scope, $http, $routeParams) { ... });
And don't forget about case sensivity! If I call it like mysite.com/confirmedemail/111/222, it won't work
不要忘记案件的敏感性!如果我把它称为mysite.com/confirmedemail/111/222,它将无法正常工作