Skip to content

Instantly share code, notes, and snippets.

@chrisortman
Created February 27, 2014 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisortman/9253653 to your computer and use it in GitHub Desktop.
Save chrisortman/9253653 to your computer and use it in GitHub Desktop.
Example of C# html builder
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"));
}
}
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);
});
});
});
});
}
}
<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>
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