Last active
December 22, 2016 16:53
-
-
Save pdwetz/4677630 to your computer and use it in GitHub Desktop.
Useful little bits for FubuMVC; rather than dig through source, keeping them here for quick reference. I'll eventually post an article with them that's better for public consumption.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If using FubuAthentication, update auth ticket as needed (e.g. account creation or key updated) | |
private readonly IAuthenticationSession _auth; | |
public SomeController(IAuthenticationSession auth) { _auth = auth; } | |
_auth.MarkAuthenticated(user.Email); | |
// If using FubuAuthentication, make route available to anonymous users | |
[NotAuthenticated] | |
public FubuContinuation SomeRoute(SomeRouteInputModel input) | |
{ | |
// Use a continuation to redirect to input-less page | |
return FubuContinuation.RedirectTo<HomeController>(x => x.HomePage()); | |
} | |
// Use the url registry to grab links (better than handcoding, as this way you're safe if app is nested) | |
private readonly UrlRegistry _urlregistry; | |
public SomeController(UrlRegistry urlreg) { _urlregistry = urlreg; } | |
// input-based route | |
string sUrl = _urlregistry.UrlFor(new SomeInputModel { Id = input.Id }) | |
// input-less route | |
string sUrl = _urlregistry.UrlFor<HomeController>(x => x.HomePage(), "GET"); | |
// Within a Spark view, you can link and add various <a> metadata (method returns an HtmlTag and can be chained) | |
${this.LinkTo[[MyNamespace.Handlers.AboutController]](c => c.AboutUs()).AddClass("nav").Text("About Us")} | |
// You can also include an image | |
${this.LinkTo[[MyNamespace.Handlers.HomeController]](c => c.HomePage()).Append(this.ImageFor("home.png"))} | |
// If you want to have a Fubu partial (which will get its own pipeline; e.g. it can utilize security, | |
// even within a route that's not authenticated | |
${this.Partial<MyNamespace.Handlers.TopNavInputModel>()} | |
// You can uses a bindings.xml file in your web apps Shared folder to utilize tags for calls | |
<element name="Image">this.ImageFor('@src')</element> | |
// With the above, instead of using ${this.ImageFor("home.png")} we can use: | |
<Image src="home.png"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment