Ajax中post后台.net MVC中Controller的路径问题。

今天使用ajax的post方法,去访问mvc的controller,url的传值是 "//ProductCatalog/PostShareInfo",发现无论如何都访问不到。

我实际想要访问的地址是“http://localhost/ProductCatalog/PostShareInfo”,而真实的访问地址是,“http://ProductCatalog/PostShareInfo”,少了localhost

原因是因为,前面多了一个/,应该为"/ProductCatalog/PostShareInfo",不是"//ProductCatalog/PostShareInfo"

根据:https://blog.csdn.net/laokaizzz/article/details/22889725,中的说明

url 参数

是 UserManage/UpdateUser  时,是去访问 http://localhost/Home/UserManage/UpdateUser 

是 ~/UserManage/UpdateUser  时,是去访问 http://localhost/Home/~/UserManage/UpdateUser   不支持~ 因为不是服务器 ,是js

是 /UserManage/UpdateUser   时,是去访问 http://localhost/UserManage/UpdateUser  

最前面写 / 是表示 根目录,不加 / 表示当前目录

而如果url地址中最前是两个/,"//",会导致访问的时候,跳过了localhost,以至于无法访问到正确的controller地址。

猜你喜欢

转载自www.cnblogs.com/tfiremeteor/p/9072833.html
今日推荐