-
Notifications
You must be signed in to change notification settings - Fork 4
Handlers
Handlers are the equivalent to MVC Controllers, except they (typically) only handle a single URL, rather than containing many MVC 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. As with most classes, they should be sealed
and internal
unless otherwise required.
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 UD.Core.Web.ViewEngines.Razor.RazorViewLocator
for more on how .cshtml
s are found.
Note that RazorViewLocator
still supports the now deprecated mechanism of searching for culture specific .cshtml
filenames. This should no longer be used.
TODO