简体   繁体   中英

404 Error in controller action methods after deploying to remote server

.JS File

$("#drpdwn").change(function ()
{
    var filter1 = document.getElementById("drpdwn").value;
    window.location = '/Controller/GetByFilter?filter=' + filter1;
});

Actionmethod in controller:

public ActionResult GetByFilter(string filter)
{
    var model = obj.GetByFilter(filter);
    return View(model);
}

This throws a 404 on server but works as expected on localhost. problem is with URL part and I have no clue how to fix it.

There are few things when you depoly on remote server, if you deploy at root then it will work ie http://www.example.com

But if you added application or virtual directory then you need to use virtual directory too.

i.e. window.location = '/[virdir]/Controller/GetByFilter?filter=' + filter1;

So best option will be use absolute url instead of relative to the application.

i.e. window.location = 'http://www.example.com/Controller/GetByFilter?filter=' +filter1;

or window.location = 'http://www.example.com/myapp/Controller/GetByFilter?filter=' +filter1;

You could use something like this

window.location.href = "@Url.Action("ActionName","ControllerName")";

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