I'd like to use razor to create a "page" that would return some HTML based upon parameters passed in via the querystring. My idea is to call this page via AJAX to load some markup into a separate page.
So, I'd do an ajax call to something like /my-page.aspx?search=sometext&page=2 and it would basically hit a razor script that would return only the HTML that I output via my custom code, which I'd then place onto that separate page.
You can use an alternative template where you call a Razor macro with your logic for listening to the parameters etc.
An alternative template is just a template, which can be used for displaying a page in an alternative fashion. It does not need to be connected to a document type.
You can create a template and call it "Proxy" for instance and enter the text "Hi".
Then you can try calling it like this http://yourdomain.com/Proxy - Then you should see "Hi" written in your browser.
Now you can create the Razor macro to handle the data you need in your ajax request.
Razor script accessible by URL?
I'd like to use razor to create a "page" that would return some HTML based upon parameters passed in via the querystring. My idea is to call this page via AJAX to load some markup into a separate page.
So, I'd do an ajax call to something like /my-page.aspx?search=sometext&page=2 and it would basically hit a razor script that would return only the HTML that I output via my custom code, which I'd then place onto that separate page.
Make sense? Is this possible?
Hi Craig
You can use an alternative template where you call a Razor macro with your logic for listening to the parameters etc.
An alternative template is just a template, which can be used for displaying a page in an alternative fashion. It does not need to be connected to a document type.
You can create a template and call it "Proxy" for instance and enter the text "Hi".
Then you can try calling it like this http://yourdomain.com/Proxy - Then you should see "Hi" written in your browser.
Now you can create the Razor macro to handle the data you need in your ajax request.
I hope this makes sense.
/Jan
Jan, this is just what I was looking for. Easy peasy!
Thank you!
--Craig
Hi Craig
Glad it worked for you :) Actually I just came across Warrens blogpost about GET/POST XML or JSON for scenarios like these where he does not recommend using the alt template. Totally forgot about that one - It might be of inspiration and use as well http://creativewebspecialist.co.uk/2013/07/16/why-i-think-your-doing-it-wrong-umbraco-alttemplate-data-views/
But the approach above is working as well but might not be as pretty as the one Warren suggests, which is more clean and the better way.
Happy coding.
/Jan
is working on a reply...