简体   繁体   English

jQuery Ajax MVC控制器URL问题

[英]Jquery Ajax MVC controller URL issue

I have a jquery code which opens a dialog. 我有一个jQuery代码,它将打开一个对话框。 This dialog is a partial view which renders from the response of a jquery Ajax call " http://test.com/ControllerA/ViewDetails ". 该对话框是一个局部视图,它从jquery Ajax调用“ http://test.com/ControllerA/ViewDetails ”的响应中呈现。 Ajax call code looks like below Ajax调用代码如下所示

$.ajax({
    url: "ViewDetails",
    type: "GET",
    dataType: "html",

The dialog box has button which has to make another Jquery Ajax call (this has go against a different controller and action). 该对话框有一个按钮,它必须进行另一个Jquery Ajax调用(这违背了不同的控制器和操作)。 Ajax code looks like below. Ajax代码如下所示。

$.ajax({
    url: "ControllerB/Search",
    type: "GET",
    dataType: "html",

The above ajax call fails to find search action because The URL will get changed to http://test.com/ContollerA/ControllerB/Search . 上面的ajax调用无法找到搜索操作,因为URL将更改为http://test.com/ContollerA/ControllerB/Search

I feel this is something related to a route config. 我觉得这与路由配置有关。 But i need some directions from you all. 但我需要你们的一些指示。

$.ajax({
    url: "@Url.Action("ViewDetails", "ControllerA")", 
    type: "GET", 
    dataType: "html",

and

$.ajax({
    url: "@Url.Action("Search", "ControllerB")", 
    type: "GET", 
    dataType: "html",

This way you're using the route table and not generating urls willy nilly 这样,您正在使用路由表,而不生成URL Willy Nilly

The best way is to use 最好的方法是使用

 url: '../ControllerA/ViewDetails'

it worked for me when the culture is in url 当网址中包含文化时,它对我有用

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

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