Search code examples
jqueryasp.netajaxasp.net-webpages

How to post data via ajax with asp.net web pages (razor)


I've started a sample projet using the tutorials located here, http://www.asp.net/web-pages/overview/getting-started/introducing-aspnet-web-pages-2/getting-started

Which is great, I'd prefer to use this sort of functionality to serve pages instead of the mvc controller method. But I still want to post data back to the server using jquery ajax calls.

I'm thinking I have to implement an mvc controller that handles just my ajax requests and doesnt serve pages.

Is this a logical approach or is there a better way? If it is logical, does anyone have a link on how to add this type of controller functionality to an existing asp.net web pages project?

Thanks


Solution

  • Web API ("doesn't serve pages") would be the way to go. I personally haven't mixed it with WebPages so this reference should be helpful.

    Not as "good", but still doable, depending on what your needs are, "it's still ASP.Net", so good old ashx (generic handler to process your requests) would work too, though, this is probably if you have simple/few "services" you want to use/invoke...

    Hth...