javascript - Get Js FormData() In Web Api -


is there trick getting formdata post request in web api? can't seem able use namevaluecollection or formdatacollection when submitting form on frontend using js formdata(). have checked http request verify form data being passed server.

js form submit

    var formdata = new formdata();     formdata.append('email', 'email@notarealemail.com');     formdata.append('password', '123');     // submit data using xmlhttprequest 

controller web api

public ihttpactionresult checkuser(formdatacollection formdata) {      //formdatacollection , namevaluecollection don't seem return key based values } 

actually, in web api controllers should check property request information post page. next can data using appropriate method: request.content.readasbytearrayasync or request.content.readasformdataasync (it's case) or request.content.readasstreamasync, etc. depends on sent data format.

or can create class respective fields , send in json way:

public ihttpactionresult checkuser(accountdata data) {  } 

and class should like:

public class accountdata {        public string email { get; set; }        public string password { get; set; } } 

Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -