Jul 18, 2015, 11:15 AM
[CLOSED] Calling Web API and accessing page serialized fields
Hi,
I want to access some page all fields values inside an ASP.NET Web API method as Dictionary, please guide how to achieve that, I want to implement a general purpose code so that ASP.NET Web API should be able to read all fields values passed from client-side as JSON on HttpRequest. This is what I have done so far but the service cannot read any field values of the page. Please guide Thanks
ASP.NET Web API controller for service myService:
I want to access some page all fields values inside an ASP.NET Web API method as Dictionary, please guide how to achieve that, I want to implement a general purpose code so that ASP.NET Web API should be able to read all fields values passed from client-side as JSON on HttpRequest. This is what I have done so far but the service cannot read any field values of the page. Please guide Thanks
ASP.NET Web API controller for service myService:
[ActionName("Test")]
[AcceptVerbs("POST", "GET")]
public string Test(HttpRequestMessage requestMessage)
{
var values = requestMessage.Content.ReadAsAsync<Dictionary<string, string>>().Result;
return string.Join(",", values.Values.Select(x => x));
}
ASP.NET Page declaration:
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server">
</ext:ResourceManager>
<div>
<ext:TextField runat="server" ID="txtName" FieldLabel="Name" />
<ext:TextField runat="server" ID="txtEmail" FieldLabel="Email" />
<ext:Button ID="btnSave" runat="server" Text="Save">
<DirectEvents>
<Click
Success="console.log(result);"
Url="/api/myService/Test"
Type="Load"
Method="POST"
CleanRequest="true"
Json="true">
</Click>
</DirectEvents>
</ext:Button>
</div>
</form>
</body>
</html>
Last edited by Daniil; Jul 23, 2015 at 5:41 AM.
Reason: [CLOSED]