简体   繁体   English

在服务器端ASP.NET上读取FormData对象

[英]read FormData object on server-side ASP.NET

I am sending an AJAX request having the "data" property being a FormData with a single key something like this: 我正在发送一个AJAX请求,其“数据”属性是具有单个键的FormData,如下所示:

var fData = new FormData($(accRegForm));
fData.append("Name", "Test Test");

$.ajax({
    type: "POST",
    data: JSON.stringify(fData),
    url: "/DataService.ashx",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    cache: false
});

Now on the server, how can I retrieve the vale of "Name" inside ASP.NET? 现在在服务器上,如何在ASP.NET中检索“名称”的标题?

Thanks 谢谢

public void ProcessRequest (HttpContext context) {

    string name = context.Request.QueryString["Name"];
    // ..
}

Since this is a POST request, I was able to read the FormData collection on server using the following : 由于这是一个POST请求,因此我可以使用以下命令读取服务器上的FormData集合:

Request.Form["Name"]

In other words, the FormData key/value pair are sent through the normal/usual request payload. 换句话说,FormData键/值对通过常规/常规请求有效负载发送。 In case of POST request, you can use Request.Form and in case of GET request, you can use Request.QueryString instead. 如果是POST请求,则可以使用Request.Form;如果是GET请求,则可以使用Request.QueryString。

HTH, Regards HTH,问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在ASP.NET的服务器端正确读取formData - Unable to read formData correctly server-side in ASP.NET 如何使用ASP.NET发送FormData并在服务器端处理它 - How to send FormData and handle it at server-side using ASP.NET 如何从jQuery对象文字中正确调用服务器端ASP.NET并将数据返回到jQuery - How to properly call server-side ASP.NET from jQuery object literal and return data to jQuery ASP.NET Core 3.1 中的数据表服务器端处理 - Datatables server-side processing in ASP.NET Core 3.1 ASP.NET:反序列化服务器端对象 - ASP.NET: Deserializing server side object 客户端(jquery)和服务器端(asp.net)应用程序都可以访问的服务 - Service that can be accessed by both client-side (jquery) and server-side (asp.net) applications 如何填补ASP.NET webforms中服务器端和客户端之间的空白? - How to fill the gap between server-side and client-side in ASP.NET webforms? ASP.NET双列表框使用JQuery更新了客户端,以及如何在服务器端检索结果 - ASP.NET dual listboxes updated client-side with JQuery, and how to retrieve the results server-side asp.net-客户端控件更改未在服务器端看到 - asp.net - client-side control changes not seen server-side 如何从客户端调用服务器端ASP.NET事件 - how to call a server-side ASP.NET event from the client-side
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM