繁体   English   中英

部署到远程服务器后控制器操作方法中的 404 错误

[英]404 Error in controller action methods after deploying to remote server

.JS文件

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

控制器中的动作方法:

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

这会在服务器上引发 404,但在本地主机上按预期工作。 问题在于 URL 部分,我不知道如何修复它。

当您在远程服务器上 depoly 时,几乎没有什么事情,如果您在 root 下部署,那么它将起作用,即http://www.example.com

但是如果您添加了应用程序或虚拟目录,那么您也需要使用虚拟目录。

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;

你可以使用这样的东西

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM