English 中文(简体)
将“ j”带入C#
原标题:using the result from jQuery into C#

I have this function in jquery which has the result array and how can I get this result array to C# code. Can anyone help me regarding this.

 function generateData() {
 var result = $( #accordion ).sortable( toArray );
 }
最佳回答

你们可以通过从文字上调来的网络方法,来同步地这样做,这样你就能够适当地界定一种网络方法,然后按照预期,要求和处理数据和潜在的回报价值。 例如:

界定网络方法:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string HandleData(object[] data)
{
    //handle data
    return string.Empty;
}

界定可再使用的jQuery书写方法,处理网络电话:

function ExecutePageMethod(page, fn, paramArray, successFn, errorFn) {
    var paramList =   ;
    if (paramArray.length > 0) {
        for (var i = 0; i < paramArray.length; i += 2) {
            if (paramList.length > 0) paramList +=  , ;
            paramList +=  "  + paramArray[i] +  ":"  + paramArray[i + 1] +  " ;
        }
    }
    paramList =  {  + paramList +  } ;
    $.ajax({
        type: "POST",
        url: page + "/" + fn,
        contentType: "application/json; charset=utf-8",
        data: paramList,
        dataType: "json",
        success: successFn,
        error: errorFn
    });
}

当然,呼吁本身:

ExecutePageMethod("Default.aspx", "HandleData", 
    ["data", result], successCallback, failureCallback);

自然,我们现在需要确保有我们的反馈方法:

function successCallback(result) {
    var parsedResult = jQuery.parseJSON(result.d);
}

function failureCallback(result) {

}
问题回答

利用隐蔽区储存结果。

<asp:HiddenField id="hfResult" runat="server" />

J Query

$( hfResult ).val(result);

C#

String result = hfResult.Value;

注 实地只能进行扼杀,因此,你可能需要使用某种掩饰器来没收你的阵列物体。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签