ASP MVC3 - HttpPost action not found after publish

后端 未结 1 930
执笔经年
执笔经年 2021-01-07 14:22

I have an ASP MVC3 application that has several HttpPost ActionResult methods. During a debug session, the methods work fine. But when I publish and view the web app in the

相关标签:
1条回答
  • 2021-01-07 14:45

    Never hardcode urls like this:

    url: '/summary/GetAreaSelTexResult',
    

    Always use url helpers when generating urls:

    url: '@Url.Action("GetAreaSelTexResult", "summary")',
    

    The reason your code doesn't work when you deploy it in a virtual directory is because the url /summary/GetAreaSelTexResult is no longer correct. You must take into account the virtual directory name now: /myappname/summary/GetAreaSelTexResult. For this reason you should never hardcode your urls but always use url helpers to generate them.

    And if this is in a separate javascript file where you cannot use server side helpers you could define a global variable in your view that will point to the correct url or use HTML5 data-* helpers on some DOM element that you are working with.

    0 讨论(0)
提交回复
热议问题