What I am trying to achieve is as follows:
Example:
I am getting the data from .js file
$scope.getdata = function(){
$http.get(urlApi).then(function(response){
$scope.AllRecords = response.data;
});
}
Now on ASP.NET MVC I am trying to achieve the record value inside ViewBag.title like below:
@{
ViewBag.title = {{ AllRecords.Name }};
}
I am unable to get the record in ViewBag.title. Please suggest the idea of achieving this if this way is not possible.
Thanks in Advance.
Following code will execute in the sever level at first
@{
ViewBag.title = {{ AllRecords.Name }};
}
then following will execute at browser level
$scope.getdata = function(){
$http.get(urlApi).then(function(response){
$scope.AllRecords = response.data;
});
}
when it comes to execute js at browser, you don't have ViewBag.title in the browser level. To achieve this. it is good to set ViewBag.title at server level. ex :
public ActionResult Index()
{
ViewBag.title = GetAllRecordes();
return View();
}