I would like to get idea about, what is the fastest and secure way to make CRUD operations (Update-Edit-insert) in samepage with Ajax in WebMatrix Razor Syntax. Is it possible to do this CRUD Operations in same razor page with ajax without GET-POST webservice or other razor page?
I tried using jquery ajax to Post-Get data from other Razor pages with Output type Json and also using WCF Webservice. But they didnt really satisfy me, because in all i need another page to serve my data.
Yes, you can do this. Each separate CRUD operation would have to be wrapped in its own conditional block. The condition can test to see if a particular name/value pair has been sent to the server via AJAX (e.g.
action=delete
oraction=update
). When returning values back to AJAX call, make sure that theContentType
of the Response is set correctly.Here's a working example -
If anything, this illustrates how bad this approach might be in terms of maintenance etc. I would always use separate cshtml files for each data operation myself,