相关疑难解决方法(0)

将多个参数传递给jQuery ajax调用

我有以下jquery代码来调用aspx页面中的webmethod

$.ajax({
    type: "POST",
    url: "popup.aspx/GetJewellerAssets",
    contentType: "application/json; charset=utf-8",
    data: '{"jewellerId":' + filter + '}',
    dataType: "json",
    success: AjaxSucceeded,
    error: AjaxFailed
});
Run Code Online (Sandbox Code Playgroud)

这是web方法签名

[WebMethod]
public static string GetJewellerAssets(int jewellerId)
{
Run Code Online (Sandbox Code Playgroud)

这很好用.

但是现在我需要将两个参数传递给web方法

新的Web方法看起来像这样

[WebMethod]
public static string GetJewellerAssets(int jewellerId, string locale)
{
}
Run Code Online (Sandbox Code Playgroud)

如何更改客户端代码以成功调用此新方法签名?

编辑:

以下2种语法有效

data: '{ "jewellerId":' + filter + ', "locale":"en" }',
Run Code Online (Sandbox Code Playgroud)

data: JSON.stringify({ jewellerId: filter, locale: locale }),
Run Code Online (Sandbox Code Playgroud)

其中filter和locale是局部变量

asp.net ajax jquery

97
推荐指数
5
解决办法
29万
查看次数

Jquery Ajax,从mvc.net控制器返回成功/错误

我想控制何时回复错误消息和成功消息,但我总是收到错误消息:

这是我想要做的:

 $.ajax({
                type: "POST",
                data: formData,
                url: "/Forms/GetJobData",
                dataType: 'json',
                contentType: false,
                processData: false,

                success: function (response) {                    
                   alert("success!") 
                },
                error: function (response) {
                   alert("error") // I'm always get this.
                }

            });
Run Code Online (Sandbox Code Playgroud)

控制器:

         [HttpPost]
            public ActionResult GetJobData(Jobs jobData)
            {

              var mimeType = jobData.File.ContentType;
              var isFileSupported = AllowedMimeTypes(mimeType);

             if (!isFileSupported){        
                     //  Error
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return Content("The attached file is not supported", MediaTypeNames.Text.Plain);    
             }
            else
              {
                    //  Success
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    return Content("Message sent!", MediaTypeNames.Text.Plain);     

               }   

            }
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc jquery

55
推荐指数
3
解决办法
15万
查看次数

如何将多个参数从ajax调用传递给MVC控制器

我有如下控制器:

public ActionResult Save(string input, string name) {
    //Some code
    return PartialView();
}
Run Code Online (Sandbox Code Playgroud)

我需要对此控制器方法进行ajax调用并传递两个参数input和value

我的ajax调用如下所示:

$.ajax({
    url: '/Home/Save',
    type: 'POST',
    async: false,
    dataType: 'text',
    processData: false,
    data: "input=" + JSON.stringify(data) + "&name =" + $("#name").val(),
    success: function (data) {
    }
});
Run Code Online (Sandbox Code Playgroud)

我无法将值传递给name参数.. name参数中的值变为null ..请帮助我..提前感谢

ajax asp.net-mvc jquery model-binding

20
推荐指数
2
解决办法
10万
查看次数

标签 统计

jquery ×3

ajax ×2

asp.net-mvc ×2

asp.net ×1

model-binding ×1