Search code examples
asp.netjqueryhttpcontextcastle-monorail

Get HttpContext from JQuery AJAX GET


My project is using Castle Monorail as a MVC framework. The problem is that Monorail requires that all controllers have a view template. I am trying to get a string back from a method on a controller via an AJAX call. The AJAX GET always returns a 500 error from the server because Monorail cannot find a view template. I have seen other examples of workarounds in which you just set the return type of the controller method to void (this signals monorail to not bother finding a view controller) and then doing something like:

Context.Response.OutputStream.Write(buffer, 0, buffer.Length);

To just write the context to the screen.

So I have the follow method and am trying to get the return string via a Jquery AJAX GET. Can someone help?

 public void Note(string id)
    {
        if (!string.IsNullOrEmpty(id))
        {
            if (notesProvider.HasNote(id))
            {
                return "{status:'200', text: '" + notesProvider.GetNote(id).Body + "'}";

            }
            else return "{status:'404', text: 'Could not find the Note by provided id [" + id + "]'}";
        }
        else return "{status:'500', text: 'Illegal request : a note id must be provided'}";
    }
}

How should I make this return void and read the return values via the HTTPCOntext?


Solution

  • All derived Monorail Controllers have access to a method called, "CancelView()". Execute this method within the method that you wish to return without using a view template.