发送表格序列化到asp.net webmethod [英] Send form serialize to asp.net webmethod

查看:67
本文介绍了发送表格序列化到asp.net webmethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该项目继续进行. .

The project continues . .

我有一个要使用jquery表单插件序列化的表单.效果很好.

I have a form that I'm serializing with the jquery form plugin. Works great.

然后,我使用jquery ajax功能发布到asp.net Web方法,以便可以将每个表单元素插入数据库中.

I am then using the jquery ajax feature to post to an asp.net web method so that each form element can be inserted into a database.

我的问题是,我该如何遍历在asp.net Web方法中通过ajax发送的每个request.form参数.如果我使用标准的Request.Form("),则会收到错误消息.这是我的代码.

My issue is this, how do I loop through each of the request.form params that is sent via ajax in the asp.net web method. If I use a standard Request.Form("") I receive an error. Here is my code.

var queryString = $('input').fieldSerialize(); 

$.ajax({
   type: "POST",
   url: "Detail.aspx/doPostTest",
   data: "{ 'txtQuery': '" + queryString + "'}",
   contentType: "application/json; charset=utf-8",
   dataType: "json",
   success: function (data) {
        var products = eval(data.d);                             
        console.log(products);
   }
});

背后的代码

<System.Web.Services.WebMethod()> _
Public Shared Function doPostTest(ByVal txtQuery As String) As String

    'Grab Request Form variables
    Request.Form("txtMember")
End Function

我在服务器端收到的错误如下:

The error I receive on the server side is the following:

无法引用的实例成员 共享方法中的类或 共享成员. .等

Cannot refer to an instance member of a class from within a shared method or shared member . . etc.

谢谢.

推荐答案

您将需要调用HttpContext.Current.Request以从静态方法访问当前的HttpRequest.

You will need to call HttpContext.Current.Request to access your current HttpRequest from static methods.

您的页面所继承的Page类包含一个实例属性Request;因此无法从您的静态方法访问此道具.

The Page class your page inherits from contains an instance property Request; therefore it's not possible to access this prop from your static methods.

这篇关于发送表格序列化到asp.net webmethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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