Post parameters to Web API .net core
Post parameters to Web API .net core
Hi everyone,
I need to load my table in submitComplete event. here is my code:
.on('submitComplete', function () {
table.ajax.url('/api/controller').load();
});
this works fine but I also want to post one parameter to my controller at server side:
public ActionResult Find([FromBody] string nameStr)
{
...
}
is there any way that I can post the parameter here with url?
thanks
This discussion has been closed.
Answers
You should just be able to that parameter to the end of the URL string. Alternatively, you could add it in
ajax.data
- this can also be a function to give you more control,Colin
Hi Colin,
ajax.data is inside the table configuration and loads the table from the begining. in my case, when user open the page, table should be empty and when they search some names then they want to see the details in the table. so I need to load the table and post parameters to the server side in a button click function. The other option for me is using ajax call which is working for me but before using it I just wanted to know if there is a better way to post parameters to server side out of table configuration.
here is my ajax call in 'submitComplete' event and it works.
Using
submitComplete
for that sounds quite complicated! Could you not just bind aninput
event handler to the search box input and in that callajax.reload()
. When combined withajax.data
which would read the data from the input, you would get the same effect (just make sure that your server-side script returns an empty array of data when there is no search term - which will be the case initially).If you are happy with your approach though, then I don't think there is really a better way of doing it - if you want to POST parameters to your controller, then
$.ajax
will do that nicely.Allan
Hi Allan,
actually it's not only the search, it's a combination of search and add new row.
so using Ajax call in submit complete worked for me. if I found a better solution I'll post it here.
Thanks,