如何在 ASP.NET ViewBag 中使用 Angular JS 括号来显示 ViewBag.title
How to use Angular JS brackets inside ASP.NET ViewBag to display the ViewBag.title
我想要实现的目标如下:
- 我正在使用 AngularJS 和 ASP.NET MVC 来构建我的项目。
- 我做了一个产品页面,需要根据产品名称显示标题。
- 在此我使用括号{{ }} 来显示产品名称。同样,我正在尝试使用括号或 ng-model 或 ng-init 或 ng-value 来显示标题 usng viewbag.title.
示例:
我正在从 .js 文件获取数据
$scope.getdata = function(){
$http.get(urlApi).then(function(response){
$scope.AllRecords = response.data;
});
}
现在在 ASP.NET MVC 上,我正在尝试在 ViewBag.title 中实现记录值,如下所示:
@{
ViewBag.title = {{ AllRecords.Name }};
}
我无法获取 ViewBag.title 中的记录。如果这种方式不可行,请提出实现这一目标的想法。
提前致谢。
以下代码首先在服务器级别执行
@{
ViewBag.title = {{ AllRecords.Name }};
}
然后以下将在浏览器级别执行
$scope.getdata = function(){
$http.get(urlApi).then(function(response){
$scope.AllRecords = response.data;
});
}
说到在浏览器执行js,你在浏览器层面没有ViewBag.title。
为了达成这个。最好在服务器级别设置 ViewBag.title。
例如:
public ActionResult Index()
{
ViewBag.title = GetAllRecordes();
return View();
}
我想要实现的目标如下:
- 我正在使用 AngularJS 和 ASP.NET MVC 来构建我的项目。
- 我做了一个产品页面,需要根据产品名称显示标题。
- 在此我使用括号{{ }} 来显示产品名称。同样,我正在尝试使用括号或 ng-model 或 ng-init 或 ng-value 来显示标题 usng viewbag.title.
示例:
我正在从 .js 文件获取数据
$scope.getdata = function(){
$http.get(urlApi).then(function(response){
$scope.AllRecords = response.data;
});
}
现在在 ASP.NET MVC 上,我正在尝试在 ViewBag.title 中实现记录值,如下所示:
@{
ViewBag.title = {{ AllRecords.Name }};
}
我无法获取 ViewBag.title 中的记录。如果这种方式不可行,请提出实现这一目标的想法。
提前致谢。
以下代码首先在服务器级别执行
@{
ViewBag.title = {{ AllRecords.Name }};
}
然后以下将在浏览器级别执行
$scope.getdata = function(){
$http.get(urlApi).then(function(response){
$scope.AllRecords = response.data;
});
}
说到在浏览器执行js,你在浏览器层面没有ViewBag.title。 为了达成这个。最好在服务器级别设置 ViewBag.title。 例如:
public ActionResult Index()
{
ViewBag.title = GetAllRecordes();
return View();
}