Cannot post successfully if not using cassini for jQuery posts in ASP.NET MVC

Cannot post successfully if not using cassini for jQuery posts in ASP.NET MVC

倾城泪 发布于 2021-11-25 字数 479 浏览 812 回复 2 原文

When I set my project to start app using Visual Studio Development server (Cassini:Port)
my jQuery posts properly to the following URL

"SomeController/SomeMethod".

When I use localhost to run with the following URLS, it does not work

"http://localhost/Store/SomeController/SomeMethod" or
"SomeController/SomeMethod".

Any one facing this kind of issue?

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不弃不离 2022-06-07 2 楼

You can create on iis yourapp.com and in [WindoewsRoot]System32driversetchost add line
127.0.0.1 yourapp.com
and now you can test your application on this url http://yourapp.com/testpage/

故事↓在人 2022-06-07 1 楼

Try using Url.Action to map the URLs so that they are correct no matter what the virtual root.

$.post( '<%= Url.Action( "SomeMethod", "SomeController" ) %>'
        data,
        function() { ...callback.. },
        'json' );

If this still doesn't work, then we'll probably need to see your routing set up. It would also be helpful to know whether ActionLinks work but jQuery AJAX doesn't. If that's the case and the URLs are the same, then you may not have the correct urls for your Javascript files. In that case, you'd want to use Url.Content to map those URLs so they are always correct.

<script type="text/javascript"
       src='<%= Url.Content( "~/Scripts/jquery-1.3.2.js' ) %>'>
</script>