![](/img/trans.png)
[英]Failed to load resource: the server responded with a status of 404 error after deploying project
[英]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.