Created
February 27, 2014 16:34
-
-
Save chrisortman/9253653 to your computer and use it in GitHub Desktop.
Example of C# html builder
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
public class LoginForm : FormView | |
{ | |
public LoginForm() | |
{ | |
this.Action = "/login"; | |
Method = "POST"; | |
AutoComplete = "off"; | |
Classes = new[] {"form-stacked"}; | |
DefineFields<LoginModel>(f => | |
{ | |
f.AddField(x => x.Username); | |
f.AddField(x => x.Password); | |
}); | |
SubmitButton | |
.AddClass("btn-primary") | |
.Text("Login"); | |
SecondaryLinks.Add(new HtmlTag("a").Text("Forgot Password?").Attr("href","/recover")); | |
} | |
} |
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
public class LoginPageView : ContentTag | |
{ | |
public bool EmailNotConfirmed { get; set; } | |
public bool CanRegister { get; set; } | |
public string ResendEmailUrl { get; set; } | |
public string RecoverPasswordUrl { get; set; } | |
public string LoginUrl { get; set; } | |
public string RegisterUrl { get; set; } | |
public string SslLogoContent { get; set; } | |
protected override void Content() | |
{ | |
tag("section",id:"login_main", children:() => | |
{ | |
if (EmailNotConfirmed) | |
{ | |
var resendView = new ResendView(); | |
resendView.Url = ResendEmailUrl; | |
append(resendView); | |
} | |
row(() => | |
{ | |
col(md:4,children: () => | |
{ | |
append(new LoginForm()); | |
}); | |
col(mdOff:1,md:3,children: () => | |
{ | |
if (CanRegister) | |
{ | |
div(() => | |
{ | |
a(href: RegisterUrl, classes: new[] {"btn", "btn-success", "btn-block", "btn-lg"}, | |
text: "Sign Up"); | |
p("You will need your most recent invoice").AddClass("help-block"); | |
}).Style("margin-top","20px"); | |
} | |
div(() => | |
{ | |
html(SslLogoContent); | |
}); | |
}); | |
}); | |
}); | |
} | |
} |
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
<section id="login_main"> | |
<div class="row"> | |
<div class="col-md-6 col-md-offset-2"> | |
<div class="alert alert-warning"> | |
<strong>Important!</strong><p>You must confirm your email address before you can sign in to | |
this site.</p><a href="/resend" class="btn btn-primary">Resend Email</a> | |
</div> | |
</div> | |
</div><div class="row"> | |
<div class="col-md-4"> | |
<form action="/login" method="POST" autocomplete="off" class="form-stacked"> | |
<div class="form-group"> | |
<label for="username" class="control-label">Username</label><input id="username" name="username" class="form-control" /> | |
</div><div class="form-group"> | |
<label for="password" class="control-label">Password</label><input id="password" name="password" class="form-control" /> | |
</div><div class="form-group"> | |
<div> | |
<button type="submit" class="btn btn-primary">Login</button><a href="/recover">Forgot Password?</a> | |
</div> | |
</div> | |
</form> | |
</div><div class="col-md-3 col-md-offset-1"> | |
<div style="margin-top:20px"> | |
<a href="/register" class="btn btn-success btn-block btn-lg">Sign Up</a><p class="help-block">You will need your most recent invoice</p> | |
</div><div> | |
<h1>YOUR LOGO</h1> | |
</div> | |
</div> | |
</div> | |
</section> |
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
public class ResendView : ContentTag | |
{ | |
protected override void Content() | |
{ | |
row(() => | |
{ | |
col(mdOff: 2,md: 6,children: () => | |
{ | |
div(children: () => | |
{ | |
strong("Important!"); | |
p(@"You must confirm your email address before you can sign in to | |
this site."); | |
a(href:Url,text:"Resend Email",classes:new[] {"btn","btn-primary"}); | |
}, classes: "alert alert-warning"); | |
}); | |
}); | |
} | |
public string Url { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment