I've used Ajax before to call webmethods or base functions but I'd like to try using Ajax to call a Razor script which will generate some HTML and then display that HTML on my page.
I'm looking for an exmple to show me how to do it.
If you are using Umbraco 6 then you can create an action in SurfaceController which returns the partial view. more here
and if you are using Umbraco 4 the way I usually do it is that I create a template and with ajax request to that template. you dont need to create a page for it, just the template would be enough.
How to call a Template or Razor script with Ajax?
I've used Ajax before to call webmethods or base functions but I'd like to try using Ajax to call a Razor script which will generate some HTML and then display that HTML on my page.
I'm looking for an exmple to show me how to do it.
Regards,
Matt
Hi Matt,
If you are using Umbraco 6 then you can create an action in SurfaceController which returns the partial view. more here
and if you are using Umbraco 4 the way I usually do it is that I create a template and with ajax request to that template. you dont need to create a page for it, just the template would be enough.
hope it gives you some idea.
Cheers
Ali
Hi Ali,
I'm using 6 with webforms.
I've given it a quick test with the template and it looks pretty easy.
With this script in my html (don't forget to add a reference to Jquery):
and this in my AjaxTest template:
the alert displayed the HTML from the template niceley.
Regards, Matt
Hi Matt,
Glad it worked.
you should be able to use the altTemplate like this:
this used to work on v4 but not sure about v6. could you try this too and let me know if that's still valid?
Thanks
Ali
No, that does not work.
Maybe it's an MVC feature not webforms.
Thanks for trying though :)
is working on a reply...