3 votes

Renderscript

Add script aliases and paths to some cshmlts you like to be able to call in the "renderscript" template:

  aliases.Add("demo","~/macroscripts/demo.cshtml");   
 
... which it makes it calleable with www.mysite.com/renderscript?a=demo

For easy adding Ajax with the help of Razor scripts.

You can for example make a script that returns json:
@{
  var x = new {foo="whatever"};
  Json.Write (x, Response.Output);
  }

And you can make a script that handles postdata, for example:

@{
  var returnValue="";
  if (IsPost)
  {
     name = Request["name"];
     // do something useful...
     returnValue = "Thank you " + name + "!";
  }
  @returnValue
}

 

// The source for this is simply a template with the following content:

<%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
 
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server"><umbraco:macro runat="server" language="razor">
@{

  var aliases = new Dictionary<string, string>();
     
  // add your script aliases here
  aliases.Add("demo","~/macroscripts/demo.cshtml");   
 
  // makes them calleable with www.mysite.com/renderscript?a=demo
 
  var alias = Request["a"];

  if (alias != null)
  {
    if (aliases.ContainsKey(alias))
    {
      @RenderPage(aliases[alias])
    }   
  }
}
</umbraco:macro></asp:Content>

Archived files

Documentation

Source code

Package owner

Jonas Eriksson

Jonas Eriksson

Jonas has 1825 karma points

Package Compatibility

This package is compatible with the following versions as reported by community members who have downloaded this package:
Untested or doesn't work on Umbraco Cloud
Version 8.18.x (untested)

You must login before you can report on package compatibility.

Previously reported to work on versions:

Package Information

  • Package owner: Jonas Eriksson
  • Created: 14/04/2011
  • Current version 1.0
  • License MIT
  • Downloads on Our: 686