weixin_33716557 2018-04-24 18:51 采纳率: 0%
浏览 56

Ajax GET发送空数据

I'm trying to get data based on what a user has selected in a drop down menu. I'm able to nab the selected value, but when I pass it to the controller in MVC 5, the data is null. Any ideas?

jQuery

LoadData($("#Dropdown").val());
function LoadData(selectedID) {
    console.log(selectedID); //displays the right ID that was selected
    $.ajax({
        url: '@Url.Action("GetData")',
        type: "GET", 
        dataType: "json", 
        contentType: 'application/json; charset=utf-8',
        data: { selectedID: selectedID}, 
        success: function (data) {...} 
        ...
    });
};

C#

public ActionResult GetData(string selectedID) 
{
    // Get data here
    return Json(results, JsonRequestBehavior. AllowGet);
} 
  • 写回答

2条回答 默认 最新

  • ℙℕℤℝ 2018-04-24 19:35
    关注

    I have the following workaround for this since I don't know why it's passing a null value to the MVC method, when that console.log() value is displaying a non-null value. It works. It's not pretty, but it works.

    I replaced the URL in the Ajax call with:

    url: '@Url.Action("GetData")?selectedID=' + selectedID
    
    评论

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法