简体   繁体   中英

Capture URL from browser in ASP.Net MVC 5 in partial view

Ok, so I have an ASP.Net MVC 5 project. Each page can contain several "Widget" aka partial views. Now I have a button in one of the partial view and when that button is clicked I want to capture the browser URL. Here is my attempt: Suppose I go to https://www.elloh.com/test below is the code behind.

    Main Page
   {
      partial view one
      {
        // some razor code
      }
      partial view two
      {
            <div>@Request.Url.ToString()</div>
            <div>@Request.Url.AbsoluteUri</div>
        <button type="button" onclick="location.href='@Url.Action("Logoff", "Security")'"> LogOff</button>
      }
   }

Points: Now I some how want to pass the https://www.olleh.com/test when the LogOff button is clicked. I have https://www.olleh.com/test in the browser tab. I know I can pass the anonymous object. But All I get is the URL pertaining to logout partial view. So the div in the second partial view displays something like https://www.olleh.com/test/partialView2 . So if I do something like below it will not work.

    <button type="button" onclick="location.href='@Url.Action("Logoff", 
"Security",  new {id = @Request.Url.ToString()})'"> LogOff</button>

PS: the code snippet is not correct syntax wise. Bear with me on this.

Expected output: Need to be able to capture Browser URL when button in partial view is clicked.

您可以使用HttpContext.Current.Request.UrlReferrer属性来完成。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM