Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I will try to make this clear. I have an action result that has a View the view use JS to get a URL of a page. I am struggling to pass that url to another Action result that contains the logic. I can't use other approach in my case. Here is the code:
<body>
       
            <div id="data">
                    data goes here:
                @ViewBag.Paramater
            </div>
  
                <script>
                    $(document).ready(function () {

                        var urlPath = top.document.location.href
                        axios.post('/something/CustomPages/62502599-ac48-42b9-b4bf-b211d0341317/Home/Data', {
                            urlValue: urlPath
                        })
                            .then(function (response) {

                                document.getElementById("data").innerHTML = response.data;

                            })
                            .catch(function (error) {
                                console.log(error);
                            });

                    });

                </script>
    </body>

this gets the data and pass it to the other view but i don't know how to pass it to the action result.

What I have tried:

Here is what I tried:
<pre>[HttpPost]
        public ActionResult Index()
        {
            return View();//this use js to get the url
        }
        [HttpPost]
        public ActionResult Data(string urlValue)
        {
           
         //How to pass the url to this Action
              Uri mainURL = new Uri(Request.Form["urlValue"]); //here is the issue
             var artifacrID = HttpUtility.ParseQueryString(mainURL.Query).Get("ArtifactID");
            int DocumentArtifact = Convert.ToInt32(artifacrID);
Posted
Updated 9-Mar-20 6:04am

1 solution

Here is the Solution:
Change this:
Uri mainURL = new Uri(Request.Form["urlValue"]); //here is the issue

To:
Uri mainURL = new Uri(urlValue);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900