我现在将详细解释问题。我必须使用控制器中的$ http方法将一些参数或对象传递给MVC Action方法Three.but here when I click Route Three链接操作方法Home Controller中的三个调用两次,第一次调用templateUrl,然后调用控制器的$ http方法。在此我想先调用控制器,然后再加载视图(templateUrl)。请让我知道解决方案在AngulrJs路由中避免调用mvc动作方法调用两次
的角代码:
app.controller('routeparamtest', function($scope, $routeParams,$http) {
$http({
url: "/Home/three",
method: "GET",
params: { id:20}
});
});
var configFunction = function ($routeProvider) {
$routeProvider.
.when('/routeThree', {
templateUrl: 'Home/Three',
controller: 'routeparamtest'
});
}
的MVC控制器代码:
public class HomeController : Controller
{
public ActionResult Three(int id = 1)
{
return View();
}
}
的HTML代码:
<ul>
<li><a href="#/routeThree" > Route Three</a></li>
</ul> <div ng-view>
的Three.cshtml代码:
some html code goes here
能否请您通过删除这些行尝试 $ HTTP({ URL: “/首页/三”, 方法: “GET”, PARAMS:{ID:20} }); 从您的控制器routeparamtest –
如果我想要传递多个参数或对象,该怎么办?我该如何做到这一点 –