Url.Action Do not compute actual url

I am trying to use Url.Action to create the correct HTTP URL based on the action of the controller as follows: $.post('@Html.Raw(Url.Action("Delete", new { id = "1" }))')

However, it does not work as expected. The actual url is fired (got it from dev tools) http://localhost:60223/CordBlood/@Html.Raw(Url.Action(%22Delete%22,%20new%20%7B%20id%20=%20%224%22%20%7D))

While I need something like this: http://localhost:60223/CordBlood/Delete/1

What am I doing wrong here?

0
source share
1 answer

I think you are trying to achieve something like this.

 <script src="@Url.Content("~/Scripts/jquery-1.5.1.js")" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $("#dropdown").change(function () { var id = $("#dropdown").val(); if (id == "") { id = 0; } var dataToSend = { Id: id }; RedirectToPage(id); }); function RedirectToPage(id) { var url = '@Url.Action("Delete", "yourController", new { Id = "__id__" })'; window.location.href = url.replace('__id__', id); } }); </script> 

Hope this gives you some idea.

0
source

All Articles