0

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?

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
Didn't understand what you were asking for, to get the query parameter passed to the page please see my latest update

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.