-
Notifications
You must be signed in to change notification settings - Fork 4
Handlers
Handlers are the equivalent to ASP.NET MVC Controllers, except they (typically) only handle a single URL, rather than containing many Actions for many URLs.
Handlers must implement IHandler
, although you almost certainly want to implement the abstract Handler
class, as it provides helpful base methods for resolving Views and other typical Handler responses.
Implementations of IHandler
are automatically discovered and wired up.
sealed class ExampleHandler : Handler
{
public IResult Get()
{
return View("ViewName");
}
}
Handlers respond to (handle) requests by having public methods on them, named in accordance with the HTTP Method they handle. These methods must be public and return an IResult
or Task<IResult>
.
public async Task<IResult> Get()
{
var thing = await this.thingRepository.GetThing();
return View("ViewThing", thing);
}
This will search for a view called foo.cshtml
within the same namespace/folder as the Handler:
public IResult Get()
{
return View("foo");
}
See Views for more on advanced view functionality
TODO