1

I referred this existing answer - but it didn't work.

I am using below piece of code to generate a fully qualified url and pass it to script and use this url there to redirect.

 @section Scripts
 {
    @Html.Script(@<script type="text/javascript">
    $(document).ready(function () {
        let targetUrl = '@Html.Raw(Url.Action("action", "controller",
            new RouteValueDictionary(new { Area = "Schemes" }),
            Request.Url.Scheme,
            Request.Url.Host))';

        let script = new ListScript(targetUrl);
        script.initialize();           
    });
    </script>)

}

http://servername:9565/Controller/ActionName //^^^^^ Extra port added and appends port number 9565 twice. What could be the possible solution to this? Why this is happening?

Shivani
  • 224
  • 5
  • 19

1 Answers1

0

Try the following in Controller.

var url = Url.Action("action", "controller", new RouteValueDictionary(new { Area = "Schemes" }), HttpContext.Request.Scheme); 

In View.

@Url.Action("Action", "Controller", new RouteValueDictionary(new { Area = "Schemes" }), Context.Request.Scheme, Context.Request.Host.ToString())

Also on a side note, do you need to wrap the Url.Action in Html.Raw, you just need the string value URL right?

kyndigs
  • 3,074
  • 1
  • 18
  • 22