javascript - Web API string parameters and POST values -


I am using a jQuery plugin. The plugin has the following functions to load the table:

  $ ('# PersonTable'). Jtable ('load', {CityId: 2, name: 'Halil'});  

The values ​​of the load functions are sent as POST data. The plugin also sends two query string parameters through the URL to paging the table for paging.

An example in the document demonstrates how to handle it in ASP.NET MVC but not in the web. API:

  [http.post] Public JSLult student listBufffitter (string) Name = "", int cdid = 0, int jettyct index = 0, int jtipixies = 0, string jtSorting = null) {try {// get data from database var student = count. Student Repository Var students = _repository.StudentRepository.GetStudentsByFilter (name, city id, jtStartIndex, jtPageSize, jtSorting); // jTable Return return results for Json (new {result = "OK", Records = students, Total records count = student count}); } Hold (exception before) {return Jason (new {result = "error", message = pre. Message}); }}  

My function currently looks: it works fine except that I can not manage reading POST data (name param):

  Public Dynamic Product List (String Name = "", Int Jetctact Index = 0, Int JetPijsies = 0) {try {int count = db.products.count (); Var products = DB from a. Products where a.ProductName.Contains (name) select one; & Lt; Products & gt; Prods = products.OrderBy (x = & gt; x.ProductID). Ollist (); Return (new {result = "OK", Records = Prod, Total record count = count}); } Hold (exception before) {return (new {result = "error", message = ex.Message}); }}  

My jTable load: (This is when the user enters text in the input)

  $ ('# ProductTable'). Jtable ('load', {name: $ ('# prodfilter'). Val ()});  

I would appreciate any help with the string parameters in the URL and how to read POST data in the Web API function.


Edit: I used an alternative method to send data to the API. Instead of sending it to the formatted load function as JSON, I used a function for the list and sent the data through the URL (see jTable API reference for details):

  ListAction: function (postData, JtParams) {return $. Inactive (function ($ dfd) {$ .ajax ({url: 'http: // localhost: 53756 / API / product / product list? JtStartIndex =' + jtParams.jtStartIndex + 'and jtPageSize =' + JtParams.jtPageSize + ' & Amp; name = '+ $ (' # prodFilter '). Val (), Type:' Post ', Datatype:' Jason ', Data: PostData, Success: Function (Data) {$ dfd resolution (data);} , Error: Work () {$ dfd.reject ();}})}}; }  

To reload the table based on your filtered results:

  $ ('# ProductTable'). Jtable ('load');  

Instead of:

  $ ('# ProductTable'). Jtable ('load', {name: $ ('# prodfilter') Val ()});    

[fromBody] to apply the attribute for the name Try the parameter

  Public Dynamic GetProductList ([FromBody] string name = "", int jtStartIndex = 0, jtPageSize = 0) {...}  

The default binder in the web API will appear in the URI for simple types, like string, which forces the body to look in.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -