这里是view1.html代码: - App.js的如何使用angularJs将路由ID传递给控制器方法?
<a href="https://stackoverflow.com/questions/{{categoty.QuestionCategoryId}}">
这里是代码: -
.when('/questions/:id', { templateUrl: 'Templates/QuestionsPage.html', controller: 'SmartLearnerController' })
这里我m到处id参数,同时点击HREF。
这里是我的.NET控制器代码在这里我想通过上面的ID: -
public JsonResult GetQuestionList(int id)
{
var data = db.GetAllQuestions().Where(a => a.QuestionID == id).ToList();
return Json(data, JsonRequestBehavior.AllowGet);
}
现在的问题是如何从App.js使用服务或angularJs的功能通过id来ASP.net控制器?
@感谢您的回复,您能解释一下如何使用controller作为依赖关系吗? –
$ routeParams是控制器的依赖项(SmartLearnerController在你的情况下)。在注入其他依赖项时注入$ routeParams。 – atinder
好的谢谢atinder :) –