Currently, I have an MVC .NET application integrated with AngularJS. In my route provider configuration, I am utilizing the controllers of MVC to retrieve the views as shown below:
.when('/Units', {
templateUrl: 'Unit/Units'
})
.when('/UnitsDetail', {
templateUrl: 'Unit/UnitsDetail'
})
My UnitController in .NET consists of the following methods:
[Authorize]
public ActionResult Units()
{
return View();
}
[Authorize]
public ActionResult UnitsDetail()
{
ViewBag.reference = Guid.NewGuid().ToString().Substring(0, 6);
return View();
}
In the UnitsDetail view, it is necessary for me to have a unique reference generated within the UnitsDetail() method.
An issue arises when navigating from Units to UnitsDetail multiple times. Initially, the UnitsDetail() method is invoked, generating a new reference. However, upon returning to Units and revisiting UnitsDetail, the method is not triggered again resulting in the same reference being displayed. It is imperative that a fresh reference is generated each time.
Although I could potentially generate the reference using JavaScript on the client side or make an AJAX request from Angular to the server, my main query revolves around how to prompt Angular to call the UnitsDetail() method whenever "#/UnitsDetail" is accessed.
Any insights or suggestions would be greatly appreciated!