Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have an app that will be started from external app possibly with a parameter (only one) coming with url. I have a following Action inside my MVC Home Controller:

    public JsonResult LoadParam()
    {
        var query = Request.Url.Query.ToString();
        string id = HttpUtility.ParseQueryString(query).Get(0);
        return Json(id);
    }

My problem is how do I call this from angular code? Normally I would use Get, but then I am passing "Home/LoadParam" url and it does not make any sense. I tried passing $location.url(), but then I won't hit LoadParam() action since my single page app stands on Home/Index URL. Not to mention that I couldn't make $location to get me any result (always getting an empty string).
So, to sum up - my question is how do I call this action from angualr code to retrieve the value of parameter when the app is open?

share|improve this question
up vote 0 down vote accepted

You need to use the $location service to get the query parameters on the client side rather than get it from the server side.

//Access via property
var id = location.search().id;
//Access as array
var id = location.search()[0];

https://docs.angularjs.org/api/ng/service/$location

share|improve this answer
    
Yes, but I really don't know what is the value of the parameter in the URL so clearly I cannot pass it to the MVC controller. This is exactly what I want to get FROM the LoadParam Action. – cAMPy Feb 18 '16 at 13:32
    
Didn't understand what you were asking for, to get the query parameter passed to the page please see my latest update – gabriel Feb 19 '16 at 8:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.