0

I have this html link:

<a href="~/building/delete/@item.BuildingId" class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="top" title="Delete" onclick="return confirm('Are you sure?')"><i class="icon ion-android-delete"></i></a>

and I am using default routing in my application.

And I have this Action:

public ActionResult Delete(int id)
{
    string url = "~/";
    if (System.Web.HttpContext.Current.Request.UrlReferrer != null)
        url = System.Web.HttpContext.Current.Request.UrlReferrer.ToString();
    try
    {
        UserRepository userRepo = new UserRepository();
        var user = userRepo.GetUser(id, 0);
        if (user != null)
        {
            return RedirectPermanent(url);
        }
        MachineRepository machineRepo = new MachineRepository();
        var machine = machineRepo.GetMachine(id, "");
        if (machine != null)
        {
            return RedirectPermanent(url);
        }
        buildingRepo.Delete(id);
    }
    catch
    {
    }
    return RedirectPermanent(url);
}

But when I click on my link the page is not redirect to Delete ActionResult and it refresh the page again. What could be wrong here?

  • What is the name of the class? Is it `BuildingController`? – npinti Dec 07 '15 at 08:14
  • 1
    try using @Url.Action() instead of "~/building/delete/@item.BuildingId" – Milad Dec 07 '15 at 08:19
  • @Milad It didn't worked. – Abolfazl Haraini Dec 07 '15 at 08:29
  • have you changed your default route configuration? Try adding an `RouteAttribute` to force the routing engine to see your action. Also add an `HttpGetAttribute` and see how it goes. – cleftheris Dec 07 '15 at 10:51
  • @cleftheris I haven't changed default routing and HttpGet didn't solve the problem . – Abolfazl Haraini Dec 07 '15 at 11:44
  • 1
    Try changing RedirectPermanent to Redirect. [Look this.](http://stackoverflow.com/questions/17517318/redirect-vs-redirectpermanent-in-asp-net-mvc) – Hamid Reza Dec 07 '15 at 13:00
  • Change the PermamentRedirects as @HamidReza suggests and also clean the browsers cache. Your problem is that your browser remembers the redirect and does not even bother to hit your delete controller again. – cleftheris Dec 07 '15 at 14:40

0 Answers0