none
How to pass URL retrieved by JS to an Action result RRS feed

  • Question

  • 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.

    Here is what I tried:

     [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);

    Thank you

      
    • Edited by Guest1993 Monday, March 9, 2020 1:25 PM
    • Moved by CoolDadTx Monday, March 9, 2020 2:23 PM ASP.NET related
    Monday, March 9, 2020 1:25 PM

All replies