[英]404 Error in controller action methods after deploying to remote server
.JS File .JS文件
$("#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.这会在服务器上引发 404,但在本地主机上按预期工作。 problem is with URL part and I have no clue how to fix it.
问题在于 URL 部分,我不知道如何修复它。
There are few things when you depoly on remote server, if you deploy at root then it will work ie http://www.example.com当您在远程服务器上 depoly 时,几乎没有什么事情,如果您在 root 下部署,那么它将起作用,即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")"; window.location.href = "@Url.Action("ActionName","ControllerName")";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.