如何通过从MVC的控制器Ajax调用多个参数 [英] How to pass multiple parameters from ajax call to mvc controller

查看:92
本文介绍了如何通过从MVC的控制器Ajax调用多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像下面的控制器:

I have the controller like the below:

 public ActionResult Save(string input, string name)
    {

        //Some code
        return PartialView();
    }

和我需要一个AJAX调用该控制器的方法,并通过两个参数输入值

And I need an ajax call to this controller method and pass the two arguments input and value

和我的ajax调用就像如下:

And my ajax call is like the below:

$.ajax({
url: '/Home/Save',
type: 'POST',
async: false,
dataType: 'text',
processData: false,

data: "input=" + JSON.stringify(data) + "&name =" + $("#name").val(),
success: function (data) {
}
});

我无法传递值的名称参数.. 在名称参数的值越来越空..请帮助我.. 在此先感谢

I am unable to pass the value to the name parameter.. the value in the name parameter is becoming null .. please help me .. Thanks in advance

推荐答案

您正在做一个HTTP POST,而是试图通过与GET查询字符串语法参数。在后,数据传递命名的参数,并且不使用参数=值放大器;富=酒吧语法。使用jQuery的Ajax方法可以让你创建一个JavaScript对象与指定的参数,例如:

You're making an HTTP POST, but trying to pass parameters with the GET query string syntax. In a POST, the data are passed as named parameters and do not use the param=value&foo=bar syntax. Using jQuery's ajax method lets you create a javascript object with the named parameters, like so:

$.ajax({
  url: '/Home/SaveChart',
  type: 'POST',
  async: false,
  dataType: 'text',
  processData: false,    
  data: { 
      input: JSON.stringify(IVRInstant.data), 
      name: $("#wrkname").val()
  },
  success: function (data) { }
});

这篇关于如何通过从MVC的控制器Ajax调用多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆