Git Product home page Git Product logo

twitterbootstrapmvc's Introduction

TwitterBootstrapMVC

TwitterBootstrapMvc

Fluent implementation of ASP.NET-MVC HTML helpers for Twitter Bootstrap.

Bootstrap 4 Notice

With the SPAs coming into the world of the web, and the release of MVC6, which suggests use of TagHelpers instead of HtmlHelpers, the adoption for TwitterBootstrapMvc has significantly dropped. There is just not enough demand for it anymore to justify spending time for the Bootstrap 4 upgrade, thus support for Bootstrap 4 is not planned anymore.


This project aims to help .NET MVC developers to write twitter bootstrap related code faster. If you'd like a jump start, watch this 6 minutes video explaining what TwitterBootstrapMVC does.

!IMPORTANT: This version of the video does not have all the latest features including support for Twitter Bootstrap 3. I've continued working on this project in a commercial version, the documentation for which you can see at TwitterBootstrapMVC.com. However, I'm leaving the code for it here for the benefit of the community.

Documentation:

Visit TwitterBootstrapMVC.com to see all the relevant information about this library.

NuGet package package ID: TwitterBootstrapMVC

Known Issue: You might get the following error when installing TwitterBootstrapMVC using NuGet:

error: could not install package 'portable.licensing 1.1.0' you are trying to install this package
into a project that targets '.netframework, version=v4.0', but the package does not contain any assembly
references that are compatible with that framework

In order to fix it, make sure you have latest NuGet since PCL support was added in NuGet 2.5 or 2.5.*

Submitting Issues:

  • Include your current code that is relevant to your situation. That probably will be code from controller, model and a view.
  • Be sure to include html that you are looking for.
  • Provide link to Bootstrap docs if you think that BMVC does not have support for some of Bootstrap's functionality
  • Be sure to describe clearly what does not work and what do you expect to get.

twitterbootstrapmvc's People

Contributors

dmitryefimenko avatar justinpierce avatar luizbon avatar nickdarnell avatar sarmaad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twitterbootstrapmvc's Issues

Add an "empty" nav type

Consider the base markup for a navbar:

<div class="navbar">
  <div class="navbar-inner">
    <a class="brand" href="#">Title</a>
    <ul class="nav">
      <li class="active"><a href="#">Home</a></li>
      <li><a href="#">Link</a></li>
      <li><a href="#">Link</a></li>
    </ul>
  </div>
</div>

I would like to use the NavBuilder to generate that <ul> tag that represents the navbar items. This works just fine today, with the exception that you cannot generate a nav that is just <ul class="nav"> -- there is always a specific NavType attached. While NavType.List does come close, the styling is subtly different and I'd like to minimize surprises.

ActionLink and Areas

Hi!
In my application i use ASP.NET MVC Areas functionality for segregation of different application parts.

To generate links i use code like this:

@Html.ActionLink("Home", "Index", "Dashboard", new { area = "Admin" }, null)

I've tried to apply TwitterBootstrapMvc for my application, but found that TwitterBootstrapMvc doesn't support Areas and ActionLink has overload for linkText, actionName and controllerName only.

Is there any workarounds?

Html.BootStrap().ValidationSummary() - arguments

Hi,

Thanks for adding the ValidationSummary helper.

But I think as of now, it does not support the arguments found in Html.ValidationSummary().
ie
Html.ValidationSummary(true) ->To hide property errors
Html.ValidationSummary("Error Message") ->Display a message before other messages
Html.ValidationSummary(true,"Error Message")

Thanks.

Submit Button

Could do with a submit button helper method that will simply return the html
<input type="submit" value="Save" class="btn" />

and when pressed will obviously just submit any form it's on.

...
@Html.Bootstrap().ControlGroup().TextBoxFor(x=>x.Name)
@Html.Bootstrap().ControlGroup().SubmitButton() // Something like this
...

-- Lee

Custom validation error markup; selected value in dropdown list

Couple of small issues.
I use now the version 2.3.2 which I've installed manually. The issues were exactly the same in the previous versions.

If I add a custom validation error message to the field in the control group, then I can see on the page not only the message itself (next to the field, same as any other validation messages), but the whole control group marked by the error style:

In the controller:

ModelState.AddModelError("LCode", "Language Code must be unique!")

The related field in the view:

@Html.Bootstrap().ControlGroup().TextBoxFor(Function(model) model.LCode)

Resulted page source:

<div class="error control-group">
<label class="control-label" for="LCode">Language Code<span class="required">*</span></label>
<div class="controls">
<input class="input-validation-error" id="LCode" name="LCode" type="text" value="AF" />
<span class="help-inline">
<span class="field-validation-error" data-valmsg-for="LCode" data-valmsg-replace="true">Language Code must be unique!</span>
</span>
</div></div>

It doesn't look bad, but there is inconsistency: error message disappears if I move to another field, but the error style doesn't.

If I have a dropdown list in the view:

@Html.Bootstrap().ControlGroup().DropDownListFor(Function(model) model.AppTypeId, ViewBag.AppTypeId))

where ViewBag.AppTypeId is a SelectList object:

ViewBag.AppTypeId = New SelectList(_db.Query(Of ApplicationType), "AppTypeId", "AppType", myapplication.AppTypeId)

the dropdown list appear but the first item is selected always.
ViewBag.ApptypeId contains the correct selectedValue. It can be seen on the page if I display ViewBag.AppTypeId.selectedValue and the following code shows dropdown list with properly selected item:

<div class="editor-label">
    @Html.LabelFor(Function(model) model.AppTypeId)
</div>
<div class="editor-field">
    @Html.DropDownList("AppTypeId", "-- Select Type --")
</div>

NavType.List generates wrong class

new Nav().Style(NavType.List) generates
class="nav nav-tab"
should be
class="nav nav-list"

also could use fluent methods for menu header:

  • List header

  • and divider:
  • Extension . FormMethod causes an error

    Extension . FormMethod causes an error:

    Error 473 'FormMethod' is ambiguous because multiple kinds of members with this name exist in class 'TwitterBootstrapMVC.Form'.

    Version 2.1.6

    pull-left & pull-right on nav UL elements?

    When creating a NavBar using Nav helpers how can I add the class "pull-right" to a Nav to move it to the right of the NavBar?

    For example....

    <div class="navbar">
                  <div class="navbar-inner">
                    <div class="container">
                      <a class="btn btn-navbar" data-toggle="collapse" data-target=".navbar-responsive-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                      </a>
                      <a class="brand" href="#">Title</a>
                      <div class="nav-collapse collapse navbar-responsive-collapse">
                        <ul class="nav">
                          <li class="active"><a href="#">Home</a></li>
                          <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
                            <ul class="dropdown-menu">
                              <li><a href="#">Action</a></li>
                              <li class="divider"></li>
                              <li class="nav-header">Nav header</li>
                              <li><a href="#">Separated link</a></li>
                            </ul>
                          </li>
                        </ul>
                        <ul class="nav pull-right">
                          <li><a href="#">Som link to the right</a></li>
                        </ul>
                      </div><!-- /.nav-collapse -->
                    </div>
                  </div><!-- /navbar-inner -->
                </div>

    Buttons in FormAction stick together

    Hi Dmitry,

    I just notice that between buttons in form action, there is no spaces, it make buttons stick close together.

    screen shot 2013-06-18 at 17-21-35

    Since I put code in the @using block, I must add

    <text> </text>

    just for a space.

    Should you put a single space between buttons? It will help a lot. Thanks

    Form constructor overload for Task<ActionResult>

    I was pretty excited to see that the new form disposable will accept an ActionResult, but it doesn't work with the async version. T4MVC now generates proper code to support async, so it would be cool if I could pass Task<ActionResult> in here, too.

    .IconPrepend(Icons.ok, true) causes NullReferenceException

    Latest version 2.1.5 from NuGet throws an exception for the code below:

    @Html.Bootstrap().SubmitButton().Text("Save").Style(ButtonStyle.Primary).IconPrepend(Icons.ok, true)

    [NullReferenceException: Object reference not set to an instance of an object.]
    TwitterBootstrapMVC.TypeExtensions.TypeExtensions.FormatHtmlAttributes(IDictionary2 htmlAttributes) +87 TwitterBootstrapMVC.Controls.BootstrapIcon.ToHtmlString() +94 TwitterBootstrapMVC.Controls.BootstrapButtonBase1.ToHtmlString() +1098
    System.Web.HttpUtility.HtmlEncode(Object value) +38

    Checkbox (hidden field) causing CSS problem

    We are using a template that allows for styled checkboxes. The problem occurs when we render the checkbox. It puts a hidden field before the required tag. If the tag does not come directly after the checkbox it will fail to render.

    This is the hidden field the code is adding..
    <input name="EnableAD" type="hidden" value="false">

    This is the non-working result. The hidden input field is rendered before our lablel tag causing it to fail.

    <label class="checkbox" for="EnableAD"><input checked="checked" class="ace-switch ace-switch-7" data-val="true" data-val-required="The EnableAD field is required." id="EnableAD" name="EnableAD" type="checkbox" value="true" /> <input name="EnableAD" type="hidden" value="false" /> <span class="required">Enable</span></label>

    This is a working result (trying to achieve this output). Notice the hidden input field is not in the label tag.

    <label class="checkbox" for="EnableAD"><input checked="checked" class="ace-switch ace-switch-7" data-val="true" data-val-required="The EnableAD field is required." id="EnableAD" name="EnableAD" type="checkbox" value="true" /> <span class="required">Enable</span></label> <input name="EnableAD" type="hidden" value="false" />

    So, what we need to find out is how to render or remove the hidden field so our label shows first instead. Any ideas?

    Add support for NavBar?

    Do you plan to add a helper to build a navbar?

    It should contain the SetLinksActiveByController and SetLinksActiveByControllerAndAction like nav does too. And allow for dropdowns, etc.

    Bootstrap 3

    Will you update TwitterBootstrapMVC for use with Bootstrap 3 ? ๐Ÿ‘

    Missing .btn in ActionLinkButton

    If I apply additional classes using HtmlAttributes like this

    Html.ActionLinkButton().HtmlAttributes(new { @class = "btn-flat" })

    then the HTML will be rendered without the .btn class like below

    <a class="btn-flat"/>

    Should the .btn always be included by default?

    DropDownListFor with different label text

    I have some classes

    class Foo 
    {
        public int id;
        public int barId;
        public virtual Bar Bar;
    }
    
    class Bar 
    {
        public int id;
        [Display(Name = "BarDispName")]
        public string name;
    }
    
    public class FooMap : EntityTypeConfiguration<Foo>
    {
        public FooMap()
        {
            // Primary Key
            this.HasKey(t => t.id);
    
            // Relationships
            this.HasRequired(t => t.Bar)
                .WithMany(t => t.Foos)
                .HasForeignKey(d => d.barId);
        }
    }
    

    The closes thing I need is

    @Html.Bootstrap().ControlGroup().DropDownListFor(m => m.barId, ViewBag.barId as IEnumerable<SelectListItem>)
    

    The problem is that generated label is 'bar Id*', but I want it to be the same as

    @Html.LabelFor(m => m.Bar.name)
    

    plus '*' if needed.

    So I suggest to add an overload to DropDownListFor with two expressions:

    • For 'Required' rules (adding *) and for attributes like

      label.for, select.{id, name, data-val-required, data-val-number}
      
    • For text of the label

    If there is a way to do it now, I would be glad to know about it.

    ListBox/ListBoxFor()

    Hi Dmitry,

    Can the ListBox/ListBoxFor() be added to the framework too? I use this option for multi select lists.

    Thanks.

    HelpText and DisplayAttribute

    It would be nice if the HelpText method would use the Description parameter from the DisplayAttribute of the property by default.

    eg.
    [Display(Name = "Name", Description = "Enter a name")]

    @Html.Bootstrap().ControlGroup().TextBoxFor(m => m.Name).HelpText()

    Could display a help-inline message of "Enter a name" next to the field.

    Problem with Modal's extensions

    1. The code
    @Using mdl = Html.Bootstrap().Begin(New Modal().Fade.Id("modalDelete"))
    End Using
    

    produces expected output:

    <div class="modal hide fade" id="modalDelete"></div>
    

    But if I add an extension .HtmlAttributes(New With {.data_test_value = "testValue"}) output will be wrong:

    <div class="fade" data-test-value="testValue"></div>
    

    How to get a button without "btn" style?

    Probably not an issue just a question.
    I want to have a closing button ("x") on the Modal dialog.
    Bootstrap has ".close" and "button.close" styles, and closing button looks like:

    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    

    But if I use the code

    @Html.Bootstrap().Button().Text("&times;").HtmlAttributes(New With {.data_dismiss = "modal", .class = "close", .aria_hidden = "true"})
    

    style "btn" is always there:

    <button type="button" class="btn   close" data-dismiss="modal" aria-hidden="true">&times;</button>
    

    Support PrependIcon for textboxes

    So that I can say

    @Html.Bootstrap().TextBoxFor(m => m.Email)
                     .Placeholder("Email")
                     .Prepend("icon-envelope")
    

    and it'd render:

    <div class="input-prepend">
      <span class="add-on">
        <i class="icon-envelope"></i>
      </span>
      <input type="text" id="" name="" PlaceHolder="Email">
    </div>
    

    License for the project?

    the nuget links to the twitterbootstrap license, but you dont have a a license file defined in this repo. Can you define a license for this project?

    HttpCompileException with 3.0.3

    After upgrade from 2.3.2 to 3.0.3 got an exception:
    error BC30456: 'Bootstrap' is not a member of 'System.Web.Mvc.HtmlHelper(Of Object)'.

    Support HTML5 input types

    Have the ability specify HTML5 input types such as <input type="email"> or <input type="url">.

    Something like

    @Html.Bootstrap().TextBoxFor(m => m.Email, "email").Placeholder("Email here")
    

    that renders:

    <input id="Email" name="Email" 
               placeholder="Email here" 
               type="email" value="">
    

    NullReferenceException when setting form type

    Setting the type on a form causes a NullReferenceException. I've distilled the error down to this base case:

    @using (Html.Bootstrap().Begin(new Form().Type(FormType.Horizontal)))
    {
    }

    Any value of FormType causes the error, except for _NotSet.

    Problem with .Label extension

    .Label extension with the .TextBoxFor

    @Using Html.Bootstrap.Begin(New Form("Create", "MyApplication").Type(FormType.Horizontal))
         @<fieldset>
            <legend>MyApplication</legend>
            @Html.Bootstrap().ControlGroup().TextBoxFor(Function(m) m.Name).Label().LabelText("aaa")
        </fieldset>
    End Using
    

    works properly - field label is replaced by "aaa".
    But if I use .Label with the .DisplayTextFor :

     @Using Html.Bootstrap.Begin(New Form("Details", "MyApplication").Type(FormType.Horizontal))
          @<fieldset>
            <legend>MyApplication</legend>
                @Html.Bootstrap().ControlGroup().DisplayTextFor(Function(model) model.Name).Label().LabelText("aaa")
        </fieldset>
    End Using
    

    there is a problem somewhere - the whole corresponding field is not shown in the form.

    data-val missing in ControlGroup()

    Hi!

    First of all, thank you VERY VERY MUCH for your work, you're a life saver!

    As my project is growing and I need to create entities with entities as properties (for example, an entity "Client" has a property "Person") I have noticed that when I try

    @Html.Bootstrap().ControlGroup().TextBoxFor(model => model.Person.Name)

    the control is created with everything (label, input and validation message area), but no validation data is created in the input!! I really don't know if I am missing something or if it is really an issue.

    Oh, if I try to create or edit a not-valid entity (like the Client above), after the server-side validation all the inputs are created with the validation data in them.

    Thanks!

    Stephan

    Icon on Nav links

    would be nice to have

    @nav.ActionLink("link text", "action").IconAppend(Icons.book)
    

    generates:

    <li><a href="/action"><i class="icon-book"></i> link text</a></li>
    

    On NavBar include "Area" in the matching for active or not.

    When using a nav bar it matches only on controller or controller+ation to determine whether to highlight a link as active.

    If you have a "Home" controller and "Index" action in multiple areas this causes multiple nav entries to be highlighted.

    Boolean parameter on .Disabled

    Add a condition boolean to the .Disabled Extention Method so we can rewrite
    if (Model.HasConfig)
    { @Html.Bootstrap().ActionLinkButton("txt", MVC.x.Config())}
    else
    { @Html.Bootstrap().ActionLinkButton("txt", MVC.x.Config()).Disabled()}

    to:
    @Html.Bootstrap().ActionLinkButton("txt", MVC.x.Config()).Disabled(!Model.HasConfig)

    Example is for button but I assume this is handy everywhere .Disabled() is used as an extention method in BMVC.

    See http://www.codeproject.com/Messages/4626151/Conditional-Fluent.aspx

    Icons on Tabs headers

    Basically allow to prepend/append icons to tab headers, something along the lines of:

    @using(var tabs = Html.Bootstrap().Begin(new Tabs("myTabs")))
    {
        tabs.Tab("Tab1").PrependIcon(Icons icon);
        tabs.Tab("Tab2").AppendIcon(Icons icon);
    
        using(tabs.BeginPanel())
        {
            ...
    }

    And that results into this markup:

    <ul id="myTabs" class="nav nav-tabs">
      <li class="active">
        <a href="#home" data-toggle="tab">
          <i class="icon-play-circle"></i>Home</a>
      </li>
      ...
    </ul>

    This also brings up another question: how to provide a hook for one-off cases like this where one would want to use the fluent syntax but also be able to tweak some of the generated output - coz I'd like to use the fluent syntax as much as possible.

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google โค๏ธ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.