weixin_33739541 2019-04-24 17:44 采纳率: 0%
浏览 100

通过JQuery访问控制器

I have a view called InvoiceTo and a Controller called Order. Using JQuery, the default URL is: url: '', and this is the result:

locahost:port/domain/order/InvoiceTo

If I change the URL: url: /Order/GetInformation, this is the result:

locahost:port/domain/order/InvoiceTo/Order/GetInformation

I've already tried lots of way to set my url, but is always wrong. This is my JQuery:

$(document).ready(function () {
        $('#InvoiceToDrop').change(function () {
            var $div = $('#modalPartial'); 
            var idcustomer = $(this).val(); 
            $.ajax({
                url: '/Order/GetInformation/' + idcustomer,
                type: 'GET',                
                success: function (data) {
                    alert(JSON.stringify(data));
                },
                error: function (error) {
                }
            })
        });
    });

What I have to do to have this URL:

locahost:port/domain/Order/GetInformation/1

  • 写回答

1条回答 默认 最新

  • weixin_33698823 2019-04-24 17:57
    关注

    You can use the UrlHelper Url.Action method in the view:

    $.ajax({ 
        url: '@Url.Action("GetInformation", "Order", new { customerId })',
        ...
    

    Or

    url: '@Url.Action("GetInformation", "Order")/' + idcustomer
    

    When the view loads @Url.Action is parsed and is replaced by the actual value.

    Advantages of using this method are that it uses the routing table rather than statically typed urls.

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?