PKD
PKD

Reputation: 707

Get values from link that brought my to the current page

I know - the first thing you're gonna say is "Use the referrer!"

But that'd be the wrong answer, and I'll explain why.

Assume you're on a page, say "Employees", that has a search. The search fields for name yield a table of employees upon submitting. In that table, the Employee Name is a clickable object, in this case a hyperlink. That link goes to an Employee Details page. On that page, there isn't really anything, because that page actually loads up a bunch of Angular data from a subpage.

So, the problem: On Employees, you click on a link:

http://localhost/EmployeeData#/details/cc30e1f8-b21c-4384-9710-e927686c925c

That link takes you to the EmployeeData controller and index view. The index view loads up details.html, which is an angular happiness full of data. It works great.

But back in the Index view, there's a tiny bit of code that tells the details where to show up, and has a breadcrumb. So in the Index ViewResult, (EmployeeData/Index.aspx), I'd like to be able to pull the GUID from the link that got you there... But when I use the referrer, it just tells me "You came from the Employee Search".

public ViewResult Index()
    {
        var vm = _vmp.GetViewModel<EmployeeDataViewModel>();

        vm.Breadcrumb = CreateBreadCrumbDisplay();

        return View(vm);
    }

public string CreateBreadCrumbDisplay()
    {
        var referrer = (Request.UrlReferrer != null) ? Request.UrlReferrer.AbsoluteUri : string.Empty;

        var curUrl = Request.ServerVariables["SCRIPT_NAME"];
        //do lots of stuff
        return theBreadCrumb;
    }

In this instance, CreateBreadCrumbDisplay just returns http://localhost/Employee. And curUrl just has "EmployeeData", thanks to all the real data stuff happening in the angular page, and not actually in the Index view.

So, what I need to do is grab the full URL, with the ID, and pass that ID into my "CreateBreadCrumbDisplay" method.

Thoughts?

Upvotes: 0

Views: 48

Answers (2)

Bricktop
Bricktop

Reputation: 1549

I think a possible solution would be to grab the URL params with $routeParams and pass it to your CreateBreadCrumbDisplay method from Angular.

If I understand your problem correctly reading up on $routeParams here should solve your problem.


Here is an example of how it should work:

First config your routes in Angular

myApp.config(function($routeProvider) {

    $routeProvider.when('/link/:GUID', {
        controller: 'SomeCtrl',
        templateUrl: 'sometemplate.html'
    });
});

Then in your controller

myApp.controller('SomeCtrl', function($scope, $routeParams) {
    console.log($routeParams);
});

Link to it from somewhere

<a href="#/link/cc30e1f8-b21c-4384-9710-e927686c925c">foo</a>

And finally the console output:

{ GUID: "cc30e1f8-b21c-4384-9710-e927686c925c" }

Upvotes: 1

katmanco
katmanco

Reputation: 1212

As long as I understand , you can use $location service , $location.absUrl(); And you may succeed this in many other ways even passing your url to action method as a parameter while submitting .

Upvotes: 0

Related Questions