Home

Plugins

To be completed

Ajax Provider

Out of the box, Vici MVC includes Ajax support, but doesn't include the javascript plumbing (framework) to call server methods. The reason is that most web developers already use some kind of javascript framework that supports ajax in one way or another.

To support Ajax in Vici MVC, a plugin needs to be registered. This plugin is a simple .NET class that implements the IAjaxProvider interface. The interface defines the following methods:

public interface IAjaxProvider
{
    string SetupFramework();
    string GenerateJavascriptClassName(string className);
    string GenerateJavascriptMethod(string url, string className, string methodName, 
                                    string[] parameters, bool includeFormData, 
                                    Dictionary<string,string> contextData);
}

All of these methods return javascript code to be included in the rendered view.

SetupFramework()

This method should generate some common javascript that will be used by the javascript code generated by the other methods of the provider plugin. This method will usually render some utility javascript functions and/or objects.

GenerateJavascriptClassName()

When an ajax method is of the form "Name1.Name2.FunctionName()", you should first generate the object "Name1.Name2". This method should create the javascript code to create these empty objects.

For example, when GenerateJavascriptClassName("Ajax.Helper") is called, the following HTML could be generated:

if (typeof Ajax == "undefined") Ajax = {}
if (typeof Ajax.Helper == "undefined") Ajax.Helper = {}

If the javascript framework you're using supports a more efficient way of creating these pseudo-namespaces, you can create your own javascript code.

GenerateJavascriptMethod()

This is the most important method to implement. It should generate a javascript function with the specified class name and method name. The parameters are:

  • url: the URL on the server to call.
  • className: the first part of the method name. It represents a class name or namespace.
  • methodName: the actual function name to generate. The complete function name should be className.methodName()
  • parameters: an array of parameter names to generate and pass to the server.
  • includeFormData: if set to true, the function should add an extra parameter as the first parameter of the function. This parameter is a refence to a form DOM element. The generated javascript should get all the fields in this form and send them to the server together with the other parameters of the ajax method.
  • contextData: contains fixed variable/value combinations to send to the server (together with the other parameters)

The javascript method should call the specified URL with the "POST" method (very important!) and the variables should be passed as form data (just like a normal form submit). The server will respond with JSON data: a single object containing either the property "value" or the value "error". When the method was successful, the value property is the return value of the method. If an error occurred, the "error" property will contain an error message (possibly the exception message).

A fully functional jQuery ajax provider is included with the source code of Vici MVC. Other providers will be made available on the Vici MVC website.

Custom Template Resolvers

Vici MVC allows you to override the default template path on demand each time a template is about to be loaded. This feature provides you with sophisticated control over template rendering and the capability of easily implementing "themes".

To use the custom resolver functionality, you need to add a class to your project which implements ITemplateResolver.

AppTemplateResolver.cs

public class AppTemplateResolver : ITemplateResolver 
{ 
    public string ResolveTemplate(string virtualPath, bool isLayout) 
    { 
                
    } 
} 

The ResolveTemplate method takes two arguments:

virtualPaththe current (unresolved) template path.
isLayouta boolean value indicating whether the template is a layout, or a view.

This method should either return null, in which case Vici MVC will use the built-in template resolver, or return a FULL path to the template file.