Skanda
Skanda

Reputation: 131

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.

Upvotes: 2

Views: 224

Answers (2)

dead_webdev
dead_webdev

Reputation: 256

You could use something like this

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

Upvotes: 0

Laxmi Lal Menaria
Laxmi Lal Menaria

Reputation: 1445

There are few things when you depoly on remote server, if you deploy at root then it will work i.e. 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;

Upvotes: 1

Related Questions