├── .gitignore ├── .nuget ├── NuGet.Config ├── NuGet.exe └── NuGet.targets ├── CONTRIBUTING.md ├── DOCUMENTATION.md ├── LICENSE.txt ├── Mvc.Bootstrap.Core ├── .gitignore ├── Buttons.cs ├── InputExtensions.cs ├── Mvc.Bootstrap.Core.csproj ├── Mvc.Bootstrap.Core.nuspec ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── Mvc.Bootstrap.Test ├── .gitignore ├── HtmlHelperTest.cs ├── InputExtensionsTest.cs ├── Mvc.Bootstrap.Test.csproj ├── MvcHelper.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── Mvc.Bootstrap.sln ├── README.md ├── appveyor.yml ├── doxygen.config ├── packages ├── .gitignore └── repositories.config └── pushDocumentation.ps1 /.gitignore: -------------------------------------------------------------------------------- 1 | obj 2 | bin 3 | bin/* 4 | deploy 5 | deploy/* 6 | _ReSharper.* 7 | *.user 8 | *.suo 9 | *.cache 10 | *.Cache 11 | Thumbs.db -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baynezy/MVC.Bootstrap/9177e9c4b443a08f2c4fd9ba06ec6bd8cfd60bc7/.nuget/NuGet.exe -------------------------------------------------------------------------------- /.nuget/NuGet.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildProjectDirectory)\..\ 5 | 6 | 7 | false 8 | 9 | 10 | false 11 | 12 | 13 | true 14 | 15 | 16 | false 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) 31 | 32 | 33 | 34 | 35 | $(SolutionDir).nuget 36 | 37 | 38 | 39 | $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config 40 | $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config 41 | 42 | 43 | 44 | $(MSBuildProjectDirectory)\packages.config 45 | $(PackagesProjectConfig) 46 | 47 | 48 | 49 | 50 | $(NuGetToolsPath)\NuGet.exe 51 | @(PackageSource) 52 | 53 | "$(NuGetExePath)" 54 | mono --runtime=v4.0.30319 "$(NuGetExePath)" 55 | 56 | $(TargetDir.Trim('\\')) 57 | 58 | -RequireConsent 59 | -NonInteractive 60 | 61 | "$(SolutionDir) " 62 | "$(SolutionDir)" 63 | 64 | 65 | $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) 66 | $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols 67 | 68 | 69 | 70 | RestorePackages; 71 | $(BuildDependsOn); 72 | 73 | 74 | 75 | 76 | $(BuildDependsOn); 77 | BuildPackage; 78 | 79 | 80 | 81 | 82 | 83 | 84 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 99 | 100 | 103 | 104 | 105 | 106 | 108 | 109 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 141 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ##Contributing## 2 | ###Pull Requests### 3 | After forking the repository please create a pull request before creating the fix. This way we can talk about how the fix will be implemeted. This will greatly increase your chance of your patch getting merged into the code base. -------------------------------------------------------------------------------- /DOCUMENTATION.md: -------------------------------------------------------------------------------- 1 | # MVC.Bootstrap 2 | 3 | This is a library project the extend the HtmlHelper class in ASP.Net MVC to allow you create forms for Twitter's Bootstrap CSS project. 4 | 5 | ## Documentation 6 | Fully navigable documentation available on [GitHub Pages](http://baynezy.github.io/MVC.Bootstrap/) 7 | 8 | ## Usage 9 | 10 | ### Install via NuGet 11 | 12 | Install-Package Mvc.Bootstrap.Core 13 | 14 | ### Make Available in Razor 15 | 16 | So you can use the extension methods in your views you need to update the web.config in your views directory to add a reference to the new .dll. 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | ### Use in your Views 32 | 33 | #### Example Model 34 | 35 | public class Item 36 | { 37 | public string Title { get; set; } 38 | public string Description { get; set; } 39 | } 40 | 41 | #### Usage in a View 42 | 43 | @model Item 44 | 45 | @using (Html.BeginForm("Index", "Home", FormMethod.Post)) 46 | { 47 | @Html.TextBoxControlGroupFor(m => m.Title) 48 | @Html.TextAreaControlGroupFor(m => m.Description) 49 | 50 | @Html.ButtonFormAction("Submit", Buttons.Primary) 51 | } 52 | 53 | This will create an ASP.Net MVC Input Extension that works with Twitter Bootstrap 3.0. This includes validation and error messages. 54 | 55 | ## Contributing 56 | 57 | ### Pull Requests 58 | 59 | After forking the repository please create a pull request before creating the fix. This way we can talk about how the fix will be implemented. This will greatly increase your chance of your patch getting merged into the code base. 60 | 61 | ## License 62 | This project is licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0). 63 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /Mvc.Bootstrap.Core/.gitignore: -------------------------------------------------------------------------------- 1 | obj 2 | bin 3 | bin/* 4 | deploy 5 | deploy/* 6 | _ReSharper.* 7 | *.csproj.user 8 | *.resharper.user 9 | *.suo 10 | *.cache 11 | *.Cache 12 | Thumbs.db 13 | *.nupkg -------------------------------------------------------------------------------- /Mvc.Bootstrap.Core/Buttons.cs: -------------------------------------------------------------------------------- 1 | namespace Mvc.Bootstrap.Core 2 | { 3 | public static class Buttons 4 | { 5 | public const int Default = 0; 6 | public const int Primary = 1; 7 | public const int Info = 2; 8 | public const int Success = 3; 9 | public const int Warning = 4; 10 | public const int Danger = 5; 11 | public const int Inverse = 6; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Mvc.Bootstrap.Core/InputExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text.RegularExpressions; 5 | using System.Web; 6 | using System.Web.Mvc; 7 | using System.Web.Mvc.Html; 8 | 9 | namespace Mvc.Bootstrap.Core 10 | { 11 | public static class InputExtensions 12 | { 13 | private const string FormActionClass = "form-actions"; 14 | private const string InverseButtonClass = "btn-inverse"; 15 | private const string DangerButtonClass = "btn-danger"; 16 | private const string WarningButtonClass = "btn-warning"; 17 | private const string SuccessButtonClass = "btn-success"; 18 | private const string InfoButtonClass = "btn-info"; 19 | private const string PrimaryButtonClass = "btn-primary"; 20 | private const string ButtonClass = "btn"; 21 | private const string LabelClass = "control-label"; 22 | private const string HelperClass = "help-block"; 23 | private const string ControlGroupClass = "form-group"; 24 | private const string ControlGroupErrorClass = "has-error"; 25 | private const string FormControlClass = "form-control"; 26 | 27 | public static MvcHtmlString BootstrapButton(this HtmlHelper htmlHelper, string label, int type) 28 | { 29 | return MvcHtmlString.Create(CreateButton(label, type).ToString()); 30 | } 31 | 32 | public static MvcHtmlString BootstrapButton(this HtmlHelper htmlHelper, string label, int type, object htmlAttributes) 33 | { 34 | return CreateButton(label, type, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 35 | } 36 | 37 | public static MvcHtmlString ButtonControlGroup(this HtmlHelper htmlHelper, string label, int type) 38 | { 39 | return BootstrapifyControlGroupButton(BootstrapButton(htmlHelper, label, type)); 40 | } 41 | 42 | public static MvcHtmlString ButtonControlGroup(this HtmlHelper htmlHelper, string label, int type, object htmlAttributes) 43 | { 44 | return BootstrapifyControlGroupButton(BootstrapButton(htmlHelper, label, type, htmlAttributes)); 45 | } 46 | 47 | public static MvcHtmlString ButtonFormAction(this HtmlHelper htmlHelper, string label, int type) 48 | { 49 | return BootstrapifyFormActionButton(BootstrapButton(htmlHelper, label, type)); 50 | } 51 | 52 | public static MvcHtmlString ButtonFormAction(this HtmlHelper htmlHelper, string label, int type, object htmlAttributes) 53 | { 54 | return BootstrapifyFormActionButton(BootstrapButton(htmlHelper, label, type, htmlAttributes)); 55 | } 56 | 57 | public static MvcHtmlString TextBoxControlGroupFor(this HtmlHelper htmlHelper, Expression> expression) 58 | { 59 | return htmlHelper.TextBoxControlGroupFor(expression, format: null); 60 | } 61 | 62 | public static MvcHtmlString TextBoxControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, string format) 63 | { 64 | return htmlHelper.TextBoxControlGroupFor(expression, format, null); 65 | } 66 | 67 | public static MvcHtmlString TextBoxControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, object htmlAttributes) 68 | { 69 | return htmlHelper.TextBoxControlGroupFor(expression, null, htmlAttributes); 70 | } 71 | 72 | public static MvcHtmlString TextBoxControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, string format, object htmlAttributes) 73 | { 74 | return htmlHelper.TextBoxControlGroupFor(expression, format, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 75 | } 76 | 77 | public static MvcHtmlString TextBoxControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, IDictionary htmlAttributes) 78 | { 79 | return htmlHelper.TextBoxControlGroupFor(expression, null, htmlAttributes); 80 | } 81 | 82 | public static MvcHtmlString TextBoxControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, string format, IDictionary htmlAttributes) 83 | { 84 | AddInputAttributes(ref htmlAttributes); 85 | var coreControl = htmlHelper.TextBoxFor(expression, htmlAttributes); 86 | var coreLabel = htmlHelper.LabelFor(expression, LabelHtmlAttributes()); 87 | 88 | return Bootstrapify(coreControl, coreLabel); 89 | } 90 | 91 | private static IDictionary LabelHtmlAttributes() 92 | { 93 | return new Dictionary {{"class", LabelClass}}; 94 | } 95 | 96 | public static MvcHtmlString PasswordControlGroupFor(this HtmlHelper htmlHelper, Expression> expression) 97 | { 98 | return PasswordControlGroupFor(htmlHelper, expression, htmlAttributes: null); 99 | } 100 | 101 | public static MvcHtmlString PasswordControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, object htmlAttributes) 102 | { 103 | return PasswordControlGroupFor(htmlHelper, expression, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 104 | } 105 | 106 | public static MvcHtmlString PasswordControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, IDictionary htmlAttributes) 107 | { 108 | AddInputAttributes(ref htmlAttributes); 109 | var coreControl = htmlHelper.PasswordFor(expression, htmlAttributes); 110 | var coreLabel = htmlHelper.LabelFor(expression, LabelHtmlAttributes()); 111 | 112 | return Bootstrapify(coreControl, coreLabel); 113 | } 114 | 115 | public static MvcHtmlString TextAreaControlGroupFor(this HtmlHelper htmlHelper, Expression> expression) 116 | { 117 | return TextAreaControlGroupFor(htmlHelper, expression, (IDictionary)null); 118 | } 119 | 120 | public static MvcHtmlString TextAreaControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, object htmlAttributes) 121 | { 122 | return TextAreaControlGroupFor(htmlHelper, expression, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 123 | } 124 | 125 | public static MvcHtmlString TextAreaControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, IDictionary htmlAttributes) 126 | { 127 | AddInputAttributes(ref htmlAttributes); 128 | var coreControl = htmlHelper.TextAreaFor(expression, htmlAttributes); 129 | var coreLabel = htmlHelper.LabelFor(expression, LabelHtmlAttributes()); 130 | 131 | return Bootstrapify(coreControl, coreLabel); 132 | } 133 | 134 | public static MvcHtmlString TextAreaControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, int rows, int columns, object htmlAttributes) 135 | { 136 | return TextAreaControlGroupFor(htmlHelper, expression, rows, columns, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 137 | } 138 | 139 | public static MvcHtmlString TextAreaControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, int rows, int columns, IDictionary htmlAttributes) 140 | { 141 | AddInputAttributes(ref htmlAttributes); 142 | var coreControl = htmlHelper.TextAreaFor(expression, rows, columns, htmlAttributes); 143 | var coreLabel = htmlHelper.LabelFor(expression, LabelHtmlAttributes()); 144 | 145 | return Bootstrapify(coreControl, coreLabel); 146 | } 147 | 148 | public static MvcHtmlString DropDownListControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, IEnumerable selectList) 149 | { 150 | return DropDownListControlGroupFor(htmlHelper, expression, selectList, null /* optionLabel */, null /* htmlAttributes */); 151 | } 152 | 153 | public static MvcHtmlString DropDownListControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, IEnumerable selectList, object htmlAttributes) 154 | { 155 | return DropDownListControlGroupFor(htmlHelper, expression, selectList, null /* optionLabel */, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 156 | } 157 | 158 | public static MvcHtmlString DropDownListControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, IEnumerable selectList, IDictionary htmlAttributes) 159 | { 160 | return DropDownListControlGroupFor(htmlHelper, expression, selectList, null /* optionLabel */, htmlAttributes); 161 | } 162 | 163 | public static MvcHtmlString DropDownListControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, IEnumerable selectList, string optionLabel) 164 | { 165 | return DropDownListControlGroupFor(htmlHelper, expression, selectList, optionLabel, null /* htmlAttributes */); 166 | } 167 | 168 | public static MvcHtmlString DropDownListControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, IEnumerable selectList, string optionLabel, object htmlAttributes) 169 | { 170 | return DropDownListControlGroupFor(htmlHelper, expression, selectList, optionLabel, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 171 | } 172 | 173 | public static MvcHtmlString DropDownListControlGroupFor(this HtmlHelper htmlHelper, Expression> expression, IEnumerable selectList, string optionLabel, IDictionary htmlAttributes) 174 | { 175 | AddInputAttributes(ref htmlAttributes); 176 | var coreControl = htmlHelper.DropDownListFor(expression, selectList, optionLabel, htmlAttributes); 177 | var coreLabel = htmlHelper.LabelFor(expression, LabelHtmlAttributes()); 178 | 179 | return Bootstrapify(coreControl, coreLabel); 180 | } 181 | 182 | private static MvcHtmlString Bootstrapify(IHtmlString coreControl, MvcHtmlString coreLabel) 183 | { 184 | var controlGroupDiv = ControlGroupDiv(); 185 | var coreHtml = coreControl.ToHtmlString(); 186 | var textBox = Bootstrapify(coreHtml); 187 | 188 | var label = coreLabel; 189 | 190 | var errorMessage = HandleErrors(textBox, controlGroupDiv); 191 | 192 | controlGroupDiv.InnerHtml = label.ToHtmlString() + coreControl.ToHtmlString() + errorMessage; 193 | 194 | return MvcHtmlString.Create(controlGroupDiv.ToString()); 195 | } 196 | 197 | private static MvcHtmlString BootstrapifyControlGroupButton(MvcHtmlString bootstrapButton) 198 | { 199 | var group = ControlGroupDiv(); 200 | group.InnerHtml = bootstrapButton.ToHtmlString(); 201 | 202 | return MvcHtmlString.Create(group.ToString()); 203 | } 204 | 205 | private static MvcHtmlString BootstrapifyFormActionButton(MvcHtmlString bootstrapButton) 206 | { 207 | var control = FormActionDiv(); 208 | control.InnerHtml = bootstrapButton.ToHtmlString(); 209 | 210 | return MvcHtmlString.Create(control.ToString()); 211 | } 212 | 213 | private static BootstrapControl Bootstrapify(string html) 214 | { 215 | var cssClass = GetClass(html); 216 | var errorMessage = GetErrorMessage(html); 217 | var id = GetId(html); 218 | 219 | return new BootstrapControl { Id = id, ErrorMessage = errorMessage, Class = cssClass }; 220 | } 221 | 222 | private static void AddInputAttributes(ref IDictionary htmlAttributes) 223 | { 224 | if (htmlAttributes == null) htmlAttributes = new Dictionary(); 225 | 226 | string classes; 227 | if (htmlAttributes.ContainsKey("class")) 228 | { 229 | classes = (string)htmlAttributes["class"]; 230 | classes += " " + FormControlClass; 231 | htmlAttributes.Remove("class"); 232 | } 233 | else 234 | { 235 | classes = FormControlClass; 236 | } 237 | 238 | htmlAttributes.Add("class", classes); 239 | } 240 | 241 | private static string HandleErrors(BootstrapControl textBox, TagBuilder controlGroupDiv) 242 | { 243 | var errorMessage = ""; 244 | 245 | if (!textBox.IsValid) 246 | { 247 | controlGroupDiv.AddCssClass(ControlGroupErrorClass); 248 | if (textBox.ErrorMessage.Length > 0) 249 | { 250 | var errorBox = new TagBuilder("span"); 251 | errorBox.AddCssClass(HelperClass); 252 | errorBox.InnerHtml = textBox.ErrorMessage; 253 | errorMessage = errorBox.ToString(); 254 | } 255 | } 256 | 257 | return errorMessage; 258 | } 259 | 260 | private static TagBuilder ControlLabel(BootstrapControl control) 261 | { 262 | var label = new TagBuilder("label"); 263 | label.AddCssClass(LabelClass); 264 | label.MergeAttribute("for", control.Id); 265 | label.InnerHtml = control.Id; 266 | 267 | return label; 268 | } 269 | 270 | private static TagBuilder ControlGroupDiv() 271 | { 272 | var controlGroupDiv = new TagBuilder("div"); 273 | controlGroupDiv.AddCssClass(ControlGroupClass); 274 | 275 | return controlGroupDiv; 276 | } 277 | 278 | private static TagBuilder FormActionDiv() 279 | { 280 | var formActionDiv = new TagBuilder("div"); 281 | formActionDiv.AddCssClass(FormActionClass); 282 | 283 | return formActionDiv; 284 | } 285 | 286 | private static string GetId(string html) 287 | { 288 | return GetAttribute("id", html); 289 | } 290 | 291 | private static string GetErrorMessage(string html) 292 | { 293 | return GetAttribute("data-val-required", html); 294 | } 295 | 296 | private static string GetClass(string html) 297 | { 298 | return GetAttribute("class", html); 299 | } 300 | 301 | private static string GetAttribute(string attribute, string html) 302 | { 303 | var value = ""; 304 | var match = Regex.Match(html, attribute + @"=""([^""]*)""", RegexOptions.IgnoreCase); 305 | if (match.Success) 306 | { 307 | value = match.Groups[1].Value; 308 | } 309 | 310 | return value; 311 | } 312 | 313 | private static TagBuilder CreateButton(string label, int type) 314 | { 315 | var button = new TagBuilder("button"); 316 | button.AddCssClass(GetButtonClass(type)); 317 | button.InnerHtml = label; 318 | return button; 319 | } 320 | 321 | private static string GetButtonClass(int type) 322 | { 323 | var cssClass = ""; 324 | switch (type) 325 | { 326 | case Buttons.Primary: 327 | cssClass = PrimaryButtonClass; 328 | break; 329 | 330 | case Buttons.Info: 331 | cssClass = InfoButtonClass; 332 | break; 333 | 334 | case Buttons.Success: 335 | cssClass = SuccessButtonClass; 336 | break; 337 | 338 | case Buttons.Warning: 339 | cssClass = WarningButtonClass; 340 | break; 341 | 342 | case Buttons.Danger: 343 | cssClass = DangerButtonClass; 344 | break; 345 | 346 | case Buttons.Inverse: 347 | cssClass = InverseButtonClass; 348 | break; 349 | } 350 | 351 | if (cssClass.Length > 0) 352 | { 353 | cssClass = ButtonClass + " " + cssClass; 354 | } 355 | else 356 | { 357 | cssClass = ButtonClass; 358 | } 359 | 360 | return cssClass; 361 | } 362 | 363 | private static MvcHtmlString CreateButton(string label, int type, IDictionary htmlAttributes) 364 | { 365 | var button = CreateButton(label, type); 366 | button.MergeAttributes(htmlAttributes); 367 | return MvcHtmlString.Create(button.ToString()); 368 | } 369 | } 370 | 371 | internal class BootstrapControl 372 | { 373 | public string Id { get; set; } 374 | 375 | public string ErrorMessage { get; set; } 376 | 377 | public string Class { get; set; } 378 | 379 | public bool IsValid 380 | { 381 | get 382 | { 383 | return !Class.Contains("input-validation-error"); 384 | } 385 | } 386 | } 387 | } 388 | -------------------------------------------------------------------------------- /Mvc.Bootstrap.Core/Mvc.Bootstrap.Core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {55BC0A1E-0595-4E35-8242-9FBF476E7557} 9 | Library 10 | Properties 11 | Mvc.Bootstrap.Core 12 | Mvc.Bootstrap.Core 13 | v4.0 14 | 512 15 | ..\ 16 | true 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | True 38 | 39 | 40 | 41 | 42 | 43 | True 44 | ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll 45 | 46 | 47 | True 48 | ..\packages\Microsoft.AspNet.Mvc.4.0.40804.0\lib\net40\System.Web.Mvc.dll 49 | 50 | 51 | True 52 | ..\packages\Microsoft.AspNet.Razor.2.0.20710.0\lib\net40\System.Web.Razor.dll 53 | 54 | 55 | True 56 | ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.dll 57 | 58 | 59 | True 60 | ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Deployment.dll 61 | 62 | 63 | True 64 | ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | Designer 81 | 82 | 83 | 84 | 85 | 86 | 87 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 88 | 89 | 90 | 91 | 98 | -------------------------------------------------------------------------------- /Mvc.Bootstrap.Core/Mvc.Bootstrap.Core.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | Twitter Bootstrap and ASP.NET MVC 7 | Simon Baynes 8 | Simon Baynes 9 | https://github.com/baynezy/MVC.Bootstrap 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | true 12 | Contains extension methods for the System.Web.Mvc.HtmlHelper class. Allowing you to use Asp.Net MVC with the Twitter Bootstrap UI Framework. 13 | 14 | Copyright 2013 15 | aspnet aspnetmvc 16 | 17 | -------------------------------------------------------------------------------- /Mvc.Bootstrap.Core/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("Mvc.Bootstrap.Core")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Mvc.Bootstrap.Core")] 12 | [assembly: AssemblyCopyright("Copyright © 2012")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("b25b0cf0-1177-4e08-a6da-2887c0b1e859")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("3.0.8.*")] 35 | -------------------------------------------------------------------------------- /Mvc.Bootstrap.Core/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Mvc.Bootstrap.Test/.gitignore: -------------------------------------------------------------------------------- 1 | obj 2 | bin 3 | bin/* 4 | deploy 5 | deploy/* 6 | _ReSharper.* 7 | *.csproj.user 8 | *.resharper.user 9 | *.suo 10 | *.cache 11 | *.Cache 12 | Thumbs.db -------------------------------------------------------------------------------- /Mvc.Bootstrap.Test/HtmlHelperTest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Globalization; 3 | using System; 4 | using System.Threading; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace Mvc.Bootstrap.Test 9 | { 10 | class HtmlHelperTest 11 | { 12 | 13 | public static readonly RouteValueDictionary AttributesDictionary = new RouteValueDictionary(new { baz = "BazValue" }); 14 | public static readonly object AttributesObjectDictionary = new { baz = "BazObjValue" }; 15 | public static readonly object AttributesObjectUnderscoresDictionary = new { foo_baz = "BazObjValue" }; 16 | 17 | public static ValueProviderResult GetValueProviderResult(object rawValue, string attemptedValue) 18 | { 19 | return new ValueProviderResult(rawValue, attemptedValue, CultureInfo.InvariantCulture); 20 | } 21 | 22 | internal static IDisposable ReplaceCulture(string currentCulture, string currentUiCulture) 23 | { 24 | var newCulture = CultureInfo.GetCultureInfo(currentCulture); 25 | var newUiCulture = CultureInfo.GetCultureInfo(currentUiCulture); 26 | var originalCulture = Thread.CurrentThread.CurrentCulture; 27 | var originalUiCulture = Thread.CurrentThread.CurrentUICulture; 28 | Thread.CurrentThread.CurrentCulture = newCulture; 29 | Thread.CurrentThread.CurrentUICulture = newUiCulture; 30 | return new CultureReplacement { OriginalCulture = originalCulture, OriginalUiCulture = originalUiCulture }; 31 | } 32 | 33 | private class CultureReplacement : IDisposable 34 | { 35 | public CultureInfo OriginalCulture; 36 | public CultureInfo OriginalUiCulture; 37 | 38 | public void Dispose() 39 | { 40 | Thread.CurrentThread.CurrentCulture = OriginalCulture; 41 | Thread.CurrentThread.CurrentUICulture = OriginalUiCulture; 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Mvc.Bootstrap.Test/InputExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Web.Mvc; 8 | using System.Web.Routing; 9 | using NUnit.Framework; 10 | using Mvc.Bootstrap.Core; 11 | using System.ComponentModel.DataAnnotations; 12 | 13 | namespace Mvc.Bootstrap.Test 14 | { 15 | [TestFixture] 16 | class InputExtensionsTest 17 | { 18 | private RouteValueDictionary _attributesDictionary; 19 | private static readonly object AttributesObjectDictionary = new { baz = "BazObjValue" }; 20 | private static readonly object AttributesObjectUnderscoresDictionary = new { foo_baz = "BazObjValue" }; 21 | private static readonly object TextAreaAttributesObjectDictionary = new { rows = "15", cols = "12" }; 22 | private static readonly object TextAreaAttributesObjectUnderscoresDictionary = new { rows = "15", cols = "12", foo_bar = "baz" }; 23 | private static readonly RouteValueDictionary TextAreaAttributesDictionary = new RouteValueDictionary(new { rows = "15", cols = "12" }); 24 | private static readonly ViewDataDictionary DropDownListViewData = new ViewDataDictionary { { "foo", "Bravo" } }; 25 | 26 | [SetUp] 27 | public void SetUp() 28 | { 29 | _attributesDictionary = new RouteValueDictionary(new {baz = "BazValue"}); 30 | } 31 | 32 | [Test] 33 | public void TextBoxControlGroupForWithNullExpressionThrows() 34 | { 35 | // Arrange 36 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 37 | Assert.Throws(() => helper.TextBoxControlGroupFor(null /* expression */)); 38 | } 39 | 40 | [Test] 41 | public void TextBoxControlGroupForWithSimpleExpression() 42 | { 43 | // Arrange 44 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 45 | 46 | // Act 47 | var html = helper.TextBoxControlGroupFor(m => m.Foo); 48 | 49 | // Assert 50 | Assert.AreEqual(@"
", html.ToHtmlString()); 51 | } 52 | 53 | [Test] 54 | public void TextBoxControlGroupForValid() 55 | { 56 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 57 | var html = helper.TextBoxControlGroupFor(m => m.Foo); 58 | 59 | Assert.AreEqual(@"
", html.ToHtmlString()); 60 | } 61 | 62 | [Test] 63 | public void TextBoxControlGroupForValid2() 64 | { 65 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 66 | var html = helper.TextBoxControlGroupFor(m => m.Bar); 67 | 68 | Assert.AreEqual(@"
", html.ToHtmlString()); 69 | } 70 | 71 | [Test] 72 | public void TextBoxControlGroupForValidWithCustomLabelValue() 73 | { 74 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewDataWithCustomLabelValue()); 75 | var html = helper.TextBoxControlGroupFor(m => m.Foo); 76 | 77 | Assert.AreEqual(@"
", html.ToHtmlString()); 78 | } 79 | 80 | [Test, Ignore("Cannot get ClientValidationRuleFactory to work. Really needs finishing")] 81 | public void TextBoxControlGroupForWithSimpleExpression_Unobtrusive() 82 | { 83 | // Arrange 84 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 85 | helper.ViewContext.ClientValidationEnabled = true; 86 | helper.ViewContext.UnobtrusiveJavaScriptEnabled = true; 87 | helper.ViewContext.FormContext = new FormContext(); 88 | //helper.ClientValidationRuleFactory = (name, metadata) => new[] { new ModelClientValidationRule { ValidationType = "type", ErrorMessage = "error" } }; 89 | 90 | // Act 91 | var html = helper.TextBoxControlGroupFor(m => m.Foo); 92 | 93 | // Assert 94 | Assert.AreEqual(@"", html.ToHtmlString()); 95 | } 96 | 97 | [Test] 98 | public void TextBoxControlGroupForWithAttributesDictionary() 99 | { 100 | // Arrange 101 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 102 | 103 | // Act 104 | var html = helper.TextBoxControlGroupFor(m => m.Foo, _attributesDictionary); 105 | 106 | // Assert 107 | Assert.AreEqual(@"
", html.ToHtmlString()); 108 | } 109 | 110 | [Test] 111 | public void TextBoxControlGroupForWithAttributesObject() 112 | { 113 | // Arrange 114 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 115 | 116 | // Act 117 | var html = helper.TextBoxControlGroupFor(m => m.Foo, AttributesObjectDictionary); 118 | 119 | // Assert 120 | Assert.AreEqual(@"
", html.ToHtmlString()); 121 | } 122 | 123 | [Test] 124 | public void TextBoxControlGroupForWithAttributesObjectWithUnderscores() 125 | { 126 | // Arrange 127 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 128 | 129 | // Act 130 | var html = helper.TextBoxControlGroupFor(m => m.Foo, AttributesObjectUnderscoresDictionary); 131 | 132 | // Assert 133 | Assert.AreEqual(@"
", html.ToHtmlString()); 134 | } 135 | 136 | [Test] 137 | public void TextBoxControlGroupForWithPrefix() 138 | { 139 | // Arrange 140 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 141 | helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix"; 142 | 143 | // Act 144 | var html = helper.TextBoxControlGroupFor(m => m.Foo); 145 | 146 | // Assert 147 | Assert.AreEqual(@"
", html.ToHtmlString()); 148 | } 149 | 150 | [Test, Ignore("This should be returning a JSON Packet")] 151 | public void TextBoxControlGroupForWithPrefixAndEmptyName() 152 | { 153 | // Arrange 154 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 155 | helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix"; 156 | 157 | // Act 158 | var html = helper.TextBoxControlGroupFor(m => m); 159 | 160 | // Assert 161 | Assert.AreEqual(@"
", html.ToHtmlString()); 162 | } 163 | 164 | [Test] 165 | public void TextBoxControlGroupForWithErrors() 166 | { 167 | // Arrange 168 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewDataWithErrors()); 169 | 170 | // Act 171 | var html = helper.TextBoxControlGroupFor(m => m.Foo, AttributesObjectDictionary); 172 | 173 | // Assert 174 | Assert.AreEqual(@"
", html.ToHtmlString()); 175 | } 176 | 177 | [Test] 178 | public void TextBoxControlGroupForWithErrorsAndCustomClass() 179 | { 180 | // Arrange 181 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewDataWithErrors()); 182 | 183 | // Act 184 | var html = helper.TextBoxControlGroupFor(m => m.Foo, new { @class = "foo-class" }); 185 | 186 | // Assert 187 | Assert.AreEqual(@"
", html.ToHtmlString()); 188 | } 189 | 190 | [Test] 191 | public void PasswordControlGroupForWithNullExpressionThrows() 192 | { 193 | // Arrange 194 | var helper = MvcHelper.GetHtmlHelper(GetPasswordViewData()); 195 | 196 | // Act & Assert 197 | Assert.Throws(() => helper.PasswordControlGroupFor(null)); 198 | } 199 | 200 | [Test] 201 | public void PasswordControlGroupForDictionaryOverridesImplicitParameters() 202 | { 203 | // Arrange 204 | var helper = MvcHelper.GetHtmlHelper(GetPasswordViewData()); 205 | 206 | // Act 207 | var html = helper.PasswordControlGroupFor(m => m.Foo, new { type = "fooType" }); 208 | 209 | // Assert 210 | Assert.AreEqual(@"
", html.ToHtmlString()); 211 | } 212 | 213 | [Test] 214 | public void PasswordControlGroupForExpressionNameOverridesDictionary() 215 | { 216 | // Arrange 217 | var helper = MvcHelper.GetHtmlHelper(GetPasswordViewData()); 218 | 219 | // Act 220 | var html = helper.PasswordControlGroupFor(m => m.Foo, new { name = "bar" }); 221 | 222 | // Assert 223 | Assert.AreEqual(@"
", html.ToHtmlString()); 224 | } 225 | 226 | [Test] 227 | public void PasswordControlGroupForWithImplicitValue() 228 | { 229 | // Arrange 230 | var helper = MvcHelper.GetHtmlHelper(GetPasswordViewData()); 231 | 232 | // Act 233 | var html = helper.PasswordControlGroupFor(m => m.Foo); 234 | 235 | // Assert 236 | Assert.AreEqual(@"
", html.ToHtmlString()); 237 | } 238 | 239 | [Test, Ignore("Cannot get ClientValidationRuleFactory to work")] 240 | public void PasswordControlGroupForWithImplicitValue_Unobtrusive() 241 | { 242 | // Arrange 243 | var helper = MvcHelper.GetHtmlHelper(GetPasswordViewData()); 244 | helper.ViewContext.ClientValidationEnabled = true; 245 | helper.ViewContext.UnobtrusiveJavaScriptEnabled = true; 246 | helper.ViewContext.FormContext = new FormContext(); 247 | //helper.ClientValidationRuleFactory = (name, metadata) => new[] { new ModelClientValidationRule { ValidationType = "type", ErrorMessage = "error" } }; 248 | 249 | // Act 250 | var html = helper.PasswordControlGroupFor(m => m.Foo); 251 | 252 | // Assert 253 | Assert.AreEqual(@"", html.ToHtmlString()); 254 | } 255 | 256 | [Test] 257 | public void PasswordControlGroupForWithDeepValueWithNullModel_Unobtrusive() 258 | { 259 | // Arrange 260 | var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); 261 | helper.ViewContext.ClientValidationEnabled = true; 262 | helper.ViewContext.UnobtrusiveJavaScriptEnabled = true; 263 | helper.ViewContext.FormContext = new FormContext(); 264 | 265 | using (HtmlHelperTest.ReplaceCulture("en-US", "en-US")) 266 | { 267 | // Act 268 | var html = helper.PasswordControlGroupFor(m => m.Contained.Foo); 269 | 270 | // Assert 271 | Assert.AreEqual(@"
", html.ToHtmlString()); 272 | } 273 | } 274 | 275 | [Test] 276 | public void PasswordControlGroupForWithAttributesDictionary() 277 | { 278 | // Arrange 279 | var helper = MvcHelper.GetHtmlHelper(GetPasswordViewData()); 280 | 281 | // Act 282 | var html = helper.PasswordControlGroupFor(m => m.Foo, _attributesDictionary); 283 | 284 | // Assert 285 | Assert.AreEqual(@"
", html.ToHtmlString()); 286 | } 287 | 288 | [Test] 289 | public void PasswordControlGroupForWithAttributesObject() 290 | { 291 | // Arrange 292 | var helper = MvcHelper.GetHtmlHelper(GetPasswordViewData()); 293 | 294 | // Act 295 | var html = helper.PasswordControlGroupFor(m => m.Foo, AttributesObjectDictionary); 296 | 297 | // Assert 298 | Assert.AreEqual(@"
", html.ToHtmlString()); 299 | } 300 | 301 | [Test] 302 | public void PasswordControlGroupForWithAttributesObjectWithUnderscores() 303 | { 304 | // Arrange 305 | var helper = MvcHelper.GetHtmlHelper(GetPasswordViewData()); 306 | 307 | // Act 308 | var html = helper.PasswordControlGroupFor(m => m.Foo, AttributesObjectUnderscoresDictionary); 309 | 310 | // Assert 311 | Assert.AreEqual(@"
", html.ToHtmlString()); 312 | } 313 | 314 | [Test] 315 | public void PasswordControlGroupForWithPrefix() 316 | { 317 | // Arrange 318 | var helper = MvcHelper.GetHtmlHelper(GetPasswordViewData()); 319 | helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix"; 320 | 321 | // Act 322 | var html = helper.PasswordControlGroupFor(m => m.Foo); 323 | 324 | // Assert 325 | Assert.AreEqual(@"
", html.ToHtmlString()); 326 | } 327 | 328 | [Test] 329 | public void PasswordControlGroupForWithViewDataErrors() 330 | { 331 | // Arrange 332 | var helper = MvcHelper.GetHtmlHelper(GetPasswordViewDataWithErrors()); 333 | 334 | // Act 335 | var html = helper.PasswordControlGroupFor(m => m.Foo, AttributesObjectDictionary); 336 | 337 | // Assert 338 | Assert.AreEqual(@"
", html.ToHtmlString()); 339 | } 340 | 341 | [Test] 342 | public void TextAreaControlGroupForWithNullExpression() 343 | { 344 | // Arrange 345 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 346 | 347 | // Act & Assert 348 | Assert.Throws(() => helper.TextAreaControlGroupFor(null /* expression */)); 349 | } 350 | 351 | [Test] 352 | public void TextAreaControlGroupForWithOutOfRangeColsThrows() 353 | { 354 | // Arrange 355 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 356 | 357 | // Act & Assert 358 | Assert.Throws(() => helper.TextAreaControlGroupFor(m => m.Foo, 0, -1, null /* htmlAttributes */)); 359 | } 360 | 361 | [Test] 362 | public void TextAreaControlGroupForWithOutOfRangeRowsThrows() 363 | { 364 | // Arrange 365 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 366 | 367 | // Act & Assert 368 | Assert.Throws(() => helper.TextAreaControlGroupFor(m => m.Foo, -1, 0, null /* htmlAttributes */)); 369 | } 370 | 371 | [Test] 372 | public void TextAreaControlGroupForParameterDictionaryMerging() 373 | { 374 | // Arrange 375 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 376 | 377 | // Act 378 | var html = helper.TextAreaControlGroupFor(m => m.Foo, new { rows = "30" }); 379 | 380 | // Assert 381 | var sb = new StringBuilder(); 382 | sb.AppendLine(@"
"); 384 | 385 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 386 | } 387 | 388 | [Test, Ignore("Cannot get ClientValidationRuleFactory to work")] 389 | public void TextAreaControlGroupForParameterDictionaryMerging_Unobtrusive() 390 | { 391 | // Arrange 392 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 393 | helper.ViewContext.ClientValidationEnabled = true; 394 | helper.ViewContext.UnobtrusiveJavaScriptEnabled = true; 395 | helper.ViewContext.FormContext = new FormContext(); 396 | ModelMetadata modelMetadata; 397 | //helper.ClientValidationRuleFactory = (name, metadata) => 398 | { 399 | //modelMetadata = metadata; 400 | //return new[] { new ModelClientValidationRule { ValidationType = "type", ErrorMessage = "error" } }; 401 | }; 402 | 403 | // Act 404 | var html = helper.TextAreaControlGroupFor(m => m.Foo, new { rows = "30" }); 405 | 406 | // Assert 407 | //Assert.NotNull(modelMetadata); 408 | //Assert.AreEqual("Foo", modelMetadata.PropertyName); 409 | Assert.AreEqual(@"", html.ToHtmlString()); 411 | } 412 | 413 | [Test] 414 | public void TextAreaControlGroupForWithDefaultAttributes() 415 | { 416 | // Arrange 417 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 418 | 419 | // Act 420 | var html = helper.TextAreaControlGroupFor(m => m.Foo); 421 | 422 | // Assert 423 | var sb = new StringBuilder(); 424 | sb.AppendLine(@"
"); 426 | 427 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 428 | } 429 | 430 | [Test] 431 | public void TextAreaControlGroupForWithZeroRowsAndColumns() 432 | { 433 | // Arrange 434 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 435 | 436 | // Act 437 | var html = helper.TextAreaControlGroupFor(m => m.Foo, 0, 0, null); 438 | 439 | // Assert 440 | var sb = new StringBuilder(); 441 | sb.AppendLine(@"
"); 443 | 444 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 445 | } 446 | 447 | [Test] 448 | public void TextAreaControlGroupForWithObjectAttributes() 449 | { 450 | // Arrange 451 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 452 | 453 | // Act 454 | var html = helper.TextAreaControlGroupFor(m => m.Foo, TextAreaAttributesObjectDictionary); 455 | 456 | // Assert 457 | var sb = new StringBuilder(); 458 | sb.AppendLine(@"
"); 460 | 461 | 462 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 463 | } 464 | 465 | [Test] 466 | public void TextAreaControlGroupForWithObjectAttributesWithUnderscores() 467 | { 468 | // Arrange 469 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 470 | 471 | // Act 472 | var html = helper.TextAreaControlGroupFor(m => m.Foo, TextAreaAttributesObjectUnderscoresDictionary); 473 | 474 | // Assert 475 | var sb = new StringBuilder(); 476 | sb.AppendLine(@"
"); 478 | 479 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 480 | } 481 | 482 | [Test] 483 | public void TextAreaControlGroupForWithDictionaryAttributes() 484 | { 485 | // Arrange 486 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 487 | 488 | // Act 489 | var html = helper.TextAreaControlGroupFor(m => m.Foo, TextAreaAttributesDictionary); 490 | 491 | // Assert 492 | var sb = new StringBuilder(); 493 | sb.AppendLine(@"
"); 495 | 496 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 497 | } 498 | 499 | [Test] 500 | public void TextAreaControlGroupForWithViewDataErrors() 501 | { 502 | // Arrange 503 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewDataWithErrors()); 504 | 505 | // Act 506 | var html = helper.TextAreaControlGroupFor(m => m.Foo, TextAreaAttributesObjectDictionary); 507 | 508 | // Assert 509 | var sb = new StringBuilder(); 510 | sb.AppendLine(@"
"); 512 | 513 | 514 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 515 | } 516 | 517 | [Test] 518 | public void TextAreaControlGroupForWithViewDataErrorsAndCustomClass() 519 | { 520 | // Arrange 521 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewDataWithErrors()); 522 | 523 | // Act 524 | var html = helper.TextAreaControlGroupFor(m => m.Foo, new { @class = "foo-class" }); 525 | 526 | // Assert 527 | var sb = new StringBuilder(); 528 | sb.AppendLine(@"
"); 530 | 531 | 532 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 533 | } 534 | 535 | [Test] 536 | public void TextAreaControlGroupForWithPrefix() 537 | { 538 | // Arrange 539 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 540 | helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix"; 541 | 542 | // Act 543 | var html = helper.TextAreaControlGroupFor(m => m.Foo); 544 | 545 | // Assert 546 | var sb = new StringBuilder(); 547 | sb.AppendLine(@"
"); 549 | 550 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 551 | } 552 | 553 | [Test] 554 | public void TextAreaControlGroupForWithPrefixAndEmptyName() 555 | { 556 | // Arrange 557 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 558 | helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix"; 559 | 560 | // Act 561 | var html = helper.TextAreaControlGroupFor(m => m); 562 | 563 | // Assert 564 | var sb = new StringBuilder(); 565 | sb.AppendLine(@"
"); 567 | 568 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 569 | } 570 | 571 | [Test] 572 | public void TextAreaControlGroupForParameterDictionaryMergingWithObjectValues() 573 | { 574 | // Arrange 575 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 576 | 577 | // Act 578 | var html = helper.TextAreaControlGroupFor(m => m.Foo, 10, 25, new { rows = "30" }); 579 | 580 | // Assert 581 | var sb = new StringBuilder(); 582 | sb.AppendLine(@"
"); 584 | 585 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 586 | } 587 | 588 | [Test] 589 | public void TextAreaControlGroupForParameterDictionaryMergingWithObjectValuesWithUnderscores() 590 | { 591 | // Arrange 592 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 593 | 594 | // Act 595 | var html = helper.TextAreaControlGroupFor(m => m.Foo, 10, 25, new { rows = "30", foo_bar = "baz" }); 596 | 597 | // Assert 598 | var sb = new StringBuilder(); 599 | sb.AppendLine(@"
"); 601 | 602 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 603 | } 604 | 605 | [Test] 606 | public void TextAreaControlGroupForParameterDictionaryMergingWithDictionaryValues() 607 | { 608 | // Arrange 609 | var helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData()); 610 | 611 | // Act 612 | var html = helper.TextAreaControlGroupFor(m => m.Foo, 10, 25, new RouteValueDictionary(new { rows = "30" })); 613 | 614 | // Assert 615 | var sb = new StringBuilder(); 616 | sb.AppendLine(@"
"); 618 | 619 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 620 | } 621 | 622 | [Test] 623 | public void DropDownListControlGroupForWithNullExpressionThrows() 624 | { 625 | // Arrange 626 | var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); 627 | var selectList = new SelectList(GetSampleAnonymousObjects(), "Letter", "FullWord", "C"); 628 | 629 | // Act & Assert 630 | Assert.Throws(() => helper.DropDownListControlGroupFor(null /* expression */, selectList)); 631 | } 632 | 633 | [Test] 634 | public void DropDownListControlGroupForUsesExplicitValueIfNotProvidedInViewData() 635 | { 636 | // Arrange 637 | var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); 638 | var selectList = new SelectList(GetSampleAnonymousObjects(), "Letter", "FullWord", "C"); 639 | 640 | // Act 641 | var html = helper.DropDownListControlGroupFor(m => m.Foo, selectList, (string)null /* optionLabel */); 642 | 643 | // Assert 644 | var sb = new StringBuilder(); 645 | sb.AppendLine(@"
"); 649 | Assert.AreEqual(sb.ToString(),html.ToHtmlString()); 650 | } 651 | 652 | [Test, Ignore("Cannot get ClientValidationRuleFactory to work. Really needs finishing")] 653 | public void DropDownListControlGroupForUsesExplicitValueIfNotProvidedInViewData_Unobtrusive() 654 | { 655 | // Arrange 656 | var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); 657 | helper.ViewContext.ClientValidationEnabled = true; 658 | helper.ViewContext.UnobtrusiveJavaScriptEnabled = true; 659 | helper.ViewContext.FormContext = new FormContext(); 660 | //helper.ClientValidationRuleFactory = (name, metadata) => new[] { new ModelClientValidationRule { ValidationType = "type", ErrorMessage = "error" } }; 661 | var selectList = new SelectList(GetSampleAnonymousObjects(), "Letter", "FullWord", "C"); 662 | 663 | // Act 664 | var html = helper.DropDownListControlGroupFor(m => m.Foo, selectList, (string)null /* optionLabel */); 665 | 666 | // Assert 667 | Assert.AreEqual( 668 | @"", 672 | html.ToHtmlString()); 673 | } 674 | 675 | [Test] 676 | public void DropDownListControlGroupForWithEnumerableModel_Unobtrusive() 677 | { 678 | // Arrange 679 | var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary>()); 680 | helper.ViewContext.ClientValidationEnabled = true; 681 | helper.ViewContext.UnobtrusiveJavaScriptEnabled = true; 682 | helper.ViewContext.FormContext = new FormContext(); 683 | helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix"; 684 | 685 | var selectList = new SelectList(GetSampleAnonymousObjects(), "Letter", "FullWord", "C"); 686 | 687 | using (HtmlHelperTest.ReplaceCulture("en-US", "en-US")) 688 | { 689 | // Act 690 | var html = helper.DropDownListControlGroupFor(m => m.ElementAt(0).Foo, selectList); 691 | 692 | // Assert 693 | Assert.AreEqual( 694 | @"
", 695 | html.ToHtmlString()); 696 | } 697 | } 698 | 699 | [Test] 700 | public void DropDownListControlGroupForUsesViewDataDefaultValue() 701 | { 702 | // Arrange 703 | var helper = MvcHelper.GetHtmlHelper(DropDownListViewData); 704 | var selectList = new SelectList(GetSampleStrings(), "Charlie"); 705 | 706 | // Act 707 | var html = helper.DropDownListControlGroupFor(m => m.Foo, selectList, (string)null /* optionLabel */); 708 | 709 | // Assert 710 | var sb = new StringBuilder(); 711 | sb.AppendLine(@"
"); 715 | 716 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 717 | } 718 | 719 | [Test] 720 | public void DropDownListControlGroupForWithAttributesDictionary() 721 | { 722 | // Arrange 723 | var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); 724 | var selectList = new SelectList(GetSampleStrings()); 725 | 726 | // Act 727 | var html = helper.DropDownListControlGroupFor(m => m.Foo, selectList, null /* optionLabel */, HtmlHelperTest.AttributesDictionary); 728 | 729 | // Assert 730 | var sb = new StringBuilder(); 731 | sb.AppendLine(@"
"); 735 | 736 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 737 | } 738 | 739 | [Test] 740 | public void DropDownListControlGroupForWithErrorsAndCustomClass() 741 | { 742 | // Arrange 743 | var helper = MvcHelper.GetHtmlHelper(GetViewDataWithErrors()); 744 | var selectList = new SelectList(GetSampleStrings()); 745 | 746 | // Act 747 | var html = helper.DropDownListControlGroupFor(m => m.Foo, selectList, null /* optionLabel */, new { @class = "foo-class" }); 748 | 749 | // Assert 750 | var sb = new StringBuilder(); 751 | sb.AppendLine(@"
"); 755 | 756 | Assert.AreEqual(sb.ToString(),html.ToHtmlString()); 757 | } 758 | 759 | [Test] 760 | public void DropDownListControlGroupForWithObjectDictionary() 761 | { 762 | // Arrange 763 | var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); 764 | var selectList = new SelectList(GetSampleStrings()); 765 | 766 | // Act 767 | var html = helper.DropDownListControlGroupFor(m => m.Foo, selectList, null /* optionLabel */, HtmlHelperTest.AttributesObjectDictionary); 768 | 769 | // Assert 770 | var sb = new StringBuilder(); 771 | sb.AppendLine(@"
"); 775 | 776 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 777 | } 778 | 779 | [Test] 780 | public void DropDownListControlGroupForWithObjectDictionaryWithUnderscores() 781 | { 782 | // Arrange 783 | var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); 784 | var selectList = new SelectList(GetSampleStrings()); 785 | 786 | // Act 787 | var html = helper.DropDownListControlGroupFor(m => m.Foo, selectList, null /* optionLabel */, HtmlHelperTest.AttributesObjectUnderscoresDictionary); 788 | 789 | // Assert 790 | var sb = new StringBuilder(); 791 | sb.AppendLine(@"
"); 795 | 796 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 797 | } 798 | 799 | [Test] 800 | public void DropDownListControlGroupForWithObjectDictionaryAndSelectListNoOptionLabel() 801 | { 802 | // Arrange 803 | var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); 804 | var selectList = new SelectList(GetSampleStrings()); 805 | 806 | // Act 807 | var html = helper.DropDownListControlGroupFor(m => m.Foo, selectList, HtmlHelperTest.AttributesObjectDictionary); 808 | 809 | // Assert 810 | var sb = new StringBuilder(); 811 | sb.AppendLine(@"
"); 815 | 816 | 817 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 818 | } 819 | 820 | [Test] 821 | public void DropDownListControlGroupForWithObjectDictionaryWithUnderscoresAndSelectListNoOptionLabel() 822 | { 823 | // Arrange 824 | var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); 825 | var selectList = new SelectList(GetSampleStrings()); 826 | 827 | // Act 828 | var html = helper.DropDownListControlGroupFor(m => m.Foo, selectList, HtmlHelperTest.AttributesObjectUnderscoresDictionary); 829 | 830 | // Assert 831 | var sb = new StringBuilder(); 832 | sb.AppendLine(@"
"); 836 | 837 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 838 | } 839 | 840 | [Test] 841 | public void DropDownListControlGroupForWithObjectDictionaryAndEmptyOptionLabel() 842 | { 843 | // Arrange 844 | var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); 845 | var selectList = new SelectList(GetSampleStrings()); 846 | 847 | // Act 848 | var html = helper.DropDownListControlGroupFor(m => m.Foo, selectList, String.Empty /* optionLabel */, HtmlHelperTest.AttributesObjectDictionary); 849 | 850 | // Assert 851 | var sb = new StringBuilder(); 852 | sb.AppendLine(@"
"); 857 | 858 | 859 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 860 | } 861 | 862 | [Test] 863 | public void DropDownListControlGroupForWithObjectDictionaryAndTitle() 864 | { 865 | // Arrange 866 | var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); 867 | var selectList = new SelectList(GetSampleStrings()); 868 | 869 | // Act 870 | var html = helper.DropDownListControlGroupFor(m => m.Foo, selectList, "[Select Something]", HtmlHelperTest.AttributesObjectDictionary); 871 | 872 | // Assert 873 | var sb = new StringBuilder(); 874 | sb.AppendLine(@"
"); 879 | 880 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 881 | } 882 | 883 | [Test] 884 | public void DropDownListControlGroupForWithIEnumerableSelectListItemSelectsDefaultFromViewData() 885 | { 886 | // Arrange 887 | var vdd = new ViewDataDictionary { { "Foo", "123456789" } }; 888 | var helper = MvcHelper.GetHtmlHelper(vdd); 889 | 890 | // Act 891 | var html = helper.DropDownListControlGroupFor(m => m.Foo, GetSampleIEnumerableObjects()); 892 | 893 | // Assert 894 | var sb = new StringBuilder(); 895 | sb.AppendLine(@"
"); 899 | 900 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 901 | } 902 | 903 | [Test] 904 | public void DropDownListControlGroupForWithListOfSelectListItemSelectsDefaultFromViewData() 905 | { 906 | // Arrange 907 | var vdd = new ViewDataDictionary { { "foo", "123456789" } }; 908 | var helper = MvcHelper.GetHtmlHelper(vdd); 909 | 910 | // Act 911 | var html = helper.DropDownListControlGroupFor(m => m.Foo, GetSampleListObjects()); 912 | 913 | // Assert 914 | var sb = new StringBuilder(); 915 | sb.AppendLine(@"
"); 919 | 920 | 921 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 922 | } 923 | 924 | [Test] 925 | public void DropDownListControlGroupForWithPrefix() 926 | { 927 | // Arrange 928 | var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); 929 | var selectList = new SelectList(GetSampleStrings()); 930 | helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix"; 931 | 932 | // Act 933 | var html = helper.DropDownListControlGroupFor(m => m.Foo, selectList, HtmlHelperTest.AttributesObjectDictionary); 934 | 935 | // Assert 936 | var sb = new StringBuilder(); 937 | sb.AppendLine(@"
"); 941 | 942 | 943 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 944 | } 945 | 946 | [Test] 947 | public void DropDownListControlGroupForWithPrefixAndEmptyName() 948 | { 949 | // Arrange 950 | var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); 951 | var selectList = new SelectList(GetSampleStrings()); 952 | helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix"; 953 | 954 | // Act 955 | var html = helper.DropDownListControlGroupFor(m => m, selectList, HtmlHelperTest.AttributesObjectDictionary); 956 | 957 | // Assert 958 | var sb = new StringBuilder(); 959 | sb.AppendLine(@"
"); 963 | 964 | 965 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 966 | } 967 | 968 | [Test] 969 | public void DropDownListControlGroupForWithPrefixAndIEnumerableSelectListItemSelectsDefaultFromViewData() 970 | { 971 | // Arrange 972 | var vdd = new ViewDataDictionary { { "foo", "123456789" } }; 973 | vdd.TemplateInfo.HtmlFieldPrefix = "MyPrefix"; 974 | var helper = MvcHelper.GetHtmlHelper(vdd); 975 | 976 | // Act 977 | var html = helper.DropDownListControlGroupFor(m => m.Foo, GetSampleIEnumerableObjects()); 978 | 979 | // Assert 980 | var sb = new StringBuilder(); 981 | sb.AppendLine(@"
"); 985 | 986 | Assert.AreEqual(sb.ToString(), html.ToHtmlString()); 987 | } 988 | 989 | [Test] 990 | public void ButtonDefaultWithAttributes() 991 | { 992 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 993 | var attributes = new { id = "search"}; 994 | 995 | var button = helper.BootstrapButton("Create", Buttons.Default, attributes); 996 | 997 | Assert.AreEqual(@"", button.ToHtmlString()); 998 | } 999 | 1000 | [Test] 1001 | public void ButtonDefault() 1002 | { 1003 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 1004 | 1005 | var button = helper.BootstrapButton("Create", Buttons.Default); 1006 | 1007 | Assert.AreEqual(@"", button.ToHtmlString()); 1008 | } 1009 | 1010 | [Test] 1011 | public void ButtonDanger() 1012 | { 1013 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 1014 | 1015 | var button = helper.BootstrapButton("Create", Buttons.Danger); 1016 | 1017 | Assert.AreEqual(@"", button.ToHtmlString()); 1018 | } 1019 | 1020 | [Test] 1021 | public void ButtonInfo() 1022 | { 1023 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 1024 | 1025 | var button = helper.BootstrapButton("Create", Buttons.Info); 1026 | 1027 | Assert.AreEqual(@"", button.ToHtmlString()); 1028 | } 1029 | 1030 | [Test] 1031 | public void ButtonInverse() 1032 | { 1033 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 1034 | 1035 | var button = helper.BootstrapButton("Create", Buttons.Inverse); 1036 | 1037 | Assert.AreEqual(@"", button.ToHtmlString()); 1038 | } 1039 | 1040 | [Test] 1041 | public void ButtonPrimary() 1042 | { 1043 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 1044 | 1045 | var button = helper.BootstrapButton("Create", Buttons.Primary); 1046 | 1047 | Assert.AreEqual(@"", button.ToHtmlString()); 1048 | } 1049 | 1050 | [Test] 1051 | public void ButtonSuccess() 1052 | { 1053 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 1054 | 1055 | var button = helper.BootstrapButton("Create", Buttons.Success); 1056 | 1057 | Assert.AreEqual(@"", button.ToHtmlString()); 1058 | } 1059 | 1060 | [Test] 1061 | public void ButtonWarning() 1062 | { 1063 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 1064 | 1065 | var button = helper.BootstrapButton("Create", Buttons.Warning); 1066 | 1067 | Assert.AreEqual(@"", button.ToHtmlString()); 1068 | } 1069 | 1070 | [Test] 1071 | public void ButtonControlGroup() 1072 | { 1073 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 1074 | 1075 | var button = helper.ButtonControlGroup("Create", Buttons.Warning); 1076 | 1077 | Assert.AreEqual(@"
", button.ToHtmlString()); 1078 | } 1079 | 1080 | [Test] 1081 | public void ButtonControlGroupWithAttributes() 1082 | { 1083 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 1084 | var attributes = new { id = "search" }; 1085 | 1086 | var button = helper.ButtonControlGroup("Create", Buttons.Warning, attributes); 1087 | 1088 | Assert.AreEqual(@"
", button.ToHtmlString()); 1089 | } 1090 | 1091 | [Test] 1092 | public void ButtonFormAction() 1093 | { 1094 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 1095 | 1096 | var button = helper.ButtonFormAction("Create", Buttons.Warning); 1097 | 1098 | Assert.AreEqual(@"
", button.ToHtmlString()); 1099 | } 1100 | 1101 | [Test] 1102 | public void ButtonFormActionWithAttributes() 1103 | { 1104 | var helper = MvcHelper.GetHtmlHelper(GetTextBoxViewData()); 1105 | var attributes = new { id = "search" }; 1106 | 1107 | var button = helper.ButtonFormAction("Create", Buttons.Warning, attributes); 1108 | 1109 | Assert.AreEqual(@"
", button.ToHtmlString()); 1110 | } 1111 | 1112 | private static ViewDataDictionary GetPasswordViewData() 1113 | { 1114 | return new ViewDataDictionary {{"Foo", "ViewDataFoo"}}; 1115 | } 1116 | 1117 | private static ViewDataDictionary GetPasswordViewDataWithErrors() 1118 | { 1119 | var viewData = new ViewDataDictionary { { "Foo", "ViewDataFoo" } }; 1120 | var modelStateFoo = new ModelState(); 1121 | modelStateFoo.Errors.Add(new ModelError("foo error 1")); 1122 | modelStateFoo.Errors.Add(new ModelError("foo error 2")); 1123 | viewData.ModelState["Foo"] = modelStateFoo; 1124 | modelStateFoo.Value = HtmlHelperTest.GetValueProviderResult("AttemptedValueFoo", "AttemptedValueFoo"); 1125 | 1126 | return viewData; 1127 | } 1128 | 1129 | private static ViewDataDictionary GetTextBoxViewDataWithErrors() 1130 | { 1131 | var viewData = new ViewDataDictionary { { "Foo", "ViewDataFoo" } }; 1132 | viewData.Model = new FooBarModel { Foo = "ViewItemFoo", Bar = "ViewItemBar" }; 1133 | var modelStateFoo = new ModelState(); 1134 | modelStateFoo.Errors.Add(new ModelError("Foo error 1")); 1135 | modelStateFoo.Errors.Add(new ModelError("Foo error 2")); 1136 | viewData.ModelState["Foo"] = modelStateFoo; 1137 | modelStateFoo.Value = HtmlHelperTest.GetValueProviderResult(new[] { "AttemptedValueFoo" }, "AttemptedValueFoo"); 1138 | 1139 | return viewData; 1140 | } 1141 | 1142 | private static ViewDataDictionary GetTextBoxViewData() 1143 | { 1144 | var viewData = new ViewDataDictionary { { "Foo", "ViewDataFoo" } }; 1145 | viewData.Model = new FooBarModel { Foo = "ViewItemFoo", Bar = "ViewItemBar" }; 1146 | 1147 | return viewData; 1148 | } 1149 | 1150 | private static ViewDataDictionary GetTextBoxViewDataWithCustomLabelValue() 1151 | { 1152 | var viewData = new ViewDataDictionary { { "Foo", "ViewDataFoo" } }; 1153 | viewData.Model = new FooBarModelWithCustomLabel() { Foo = "ViewItemFoo", Bar = "ViewItemBar" }; 1154 | 1155 | return viewData; 1156 | } 1157 | 1158 | private static ViewDataDictionary GetTextAreaViewData() 1159 | { 1160 | var viewData = new ViewDataDictionary { { "Foo", "ViewDataFoo" } }; 1161 | viewData.Model = new TextAreaModel { Foo = "ViewItemFoo", Bar = "ViewItemBar" }; 1162 | return viewData; 1163 | } 1164 | 1165 | private static ViewDataDictionary GetTextAreaViewDataWithErrors() 1166 | { 1167 | var viewData = new ViewDataDictionary { { "Foo", "ViewDataFoo" } }; 1168 | viewData.Model = new TextAreaModel { Foo = "ViewItemFoo", Bar = "ViewItemBar" }; 1169 | 1170 | var modelStateFoo = new ModelState(); 1171 | modelStateFoo.Errors.Add(new ModelError("Foo error 1")); 1172 | modelStateFoo.Errors.Add(new ModelError("Foo error 2")); 1173 | viewData.ModelState["Foo"] = modelStateFoo; 1174 | modelStateFoo.Value = HtmlHelperTest.GetValueProviderResult(new[] { "AttemptedValueFoo" }, "AttemptedValueFoo"); 1175 | 1176 | return viewData; 1177 | } 1178 | 1179 | private static IEnumerable GetSampleAnonymousObjects() 1180 | { 1181 | return new[] 1182 | { 1183 | new { Letter = 'A', FullWord = "Alpha" }, 1184 | new { Letter = 'B', FullWord = "Bravo" }, 1185 | new { Letter = 'C', FullWord = "Charlie" } 1186 | }; 1187 | } 1188 | 1189 | private static IEnumerable GetSampleListObjects() 1190 | { 1191 | const string selectedSsn = "111111111"; 1192 | 1193 | return GetSamplePeople().Select(person => new SelectListItem 1194 | { 1195 | Text = person.FirstName, Value = person.Ssn, Selected = String.Equals(person.Ssn, selectedSsn) 1196 | }).ToList(); 1197 | } 1198 | 1199 | private static IEnumerable GetSampleStrings() 1200 | { 1201 | return new[] { "Alpha", "Bravo", "Charlie" }; 1202 | } 1203 | 1204 | private static IEnumerable GetSampleIEnumerableObjects() 1205 | { 1206 | var people = GetSamplePeople(); 1207 | 1208 | const string selectedSsn = "111111111"; 1209 | var list = from person in people 1210 | select new SelectListItem 1211 | { 1212 | Text = person.FirstName, 1213 | Value = person.Ssn, 1214 | Selected = String.Equals(person.Ssn, selectedSsn) 1215 | }; 1216 | return list; 1217 | } 1218 | 1219 | private static ViewDataDictionary GetViewDataWithErrors() 1220 | { 1221 | var viewData = new ViewDataDictionary { { "Foo", "ViewDataFoo" } }; 1222 | viewData.Model = new FooBarModel { Foo = "ViewItemFoo", Bar = "ViewItemBar" }; 1223 | 1224 | var modelStateFoo = new ModelState(); 1225 | modelStateFoo.Errors.Add(new ModelError("Foo error 1")); 1226 | modelStateFoo.Errors.Add(new ModelError("Foo error 2")); 1227 | viewData.ModelState["Foo"] = modelStateFoo; 1228 | modelStateFoo.Value = new ValueProviderResult(new[] { "Bravo", "Charlie" }, "Bravo", CultureInfo.InvariantCulture); 1229 | 1230 | return viewData; 1231 | } 1232 | 1233 | private class RequiredModel 1234 | { 1235 | [Required] 1236 | public string Foo { get; set; } 1237 | } 1238 | 1239 | internal static Person[] GetSamplePeople() 1240 | { 1241 | return new[] 1242 | { 1243 | new Person 1244 | { 1245 | FirstName = "John", 1246 | Ssn = "123456789" 1247 | }, 1248 | new Person 1249 | { 1250 | FirstName = "Jane", 1251 | Ssn = "987654321" 1252 | }, 1253 | new Person 1254 | { 1255 | FirstName = "Joe", 1256 | Ssn = "111111111" 1257 | } 1258 | }; 1259 | } 1260 | 1261 | internal class Person 1262 | { 1263 | public string FirstName { get; set; } 1264 | 1265 | public string Ssn { get; set; } 1266 | } 1267 | } 1268 | 1269 | 1270 | 1271 | internal class TextAreaModel 1272 | { 1273 | public string Foo { get; set; } 1274 | public string Bar { get; set; } 1275 | } 1276 | 1277 | 1278 | internal class DeepContainerModel 1279 | { 1280 | public ShallowModel Contained { get; set; } 1281 | } 1282 | 1283 | internal class ShallowModel 1284 | { 1285 | [Required] 1286 | public string Foo { get; set; } 1287 | } 1288 | 1289 | internal class FooModel 1290 | { 1291 | public string Foo { get; set; } 1292 | } 1293 | 1294 | internal class FooBarModel 1295 | { 1296 | public string Foo { get; set; } 1297 | 1298 | public string Bar { get; set; } 1299 | } 1300 | 1301 | internal class FooBarModelWithCustomLabel 1302 | { 1303 | [Display(Name="FooLabel")] 1304 | public string Foo { get; set; } 1305 | 1306 | public string Bar { get; set; } 1307 | } 1308 | } 1309 | -------------------------------------------------------------------------------- /Mvc.Bootstrap.Test/Mvc.Bootstrap.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {CEA9E4AB-2805-41EF-B50A-FD5A173781EF} 9 | Library 10 | Properties 11 | Mvc.Bootstrap.Test 12 | Mvc.Bootstrap.Test 13 | v4.0 14 | 512 15 | ..\ 16 | true 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | True 38 | ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll 39 | 40 | 41 | ..\packages\Moq.4.2.1502.0911\lib\net40\Moq.dll 42 | 43 | 44 | ..\packages\NUnit.3.0.1\lib\net40\nunit.framework.dll 45 | True 46 | 47 | 48 | 49 | 50 | 51 | 52 | True 53 | ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll 54 | 55 | 56 | True 57 | ..\packages\Microsoft.AspNet.Mvc.4.0.40804.0\lib\net40\System.Web.Mvc.dll 58 | 59 | 60 | True 61 | ..\packages\Microsoft.AspNet.Razor.2.0.20710.0\lib\net40\System.Web.Razor.dll 62 | 63 | 64 | True 65 | ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.dll 66 | 67 | 68 | True 69 | ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Deployment.dll 70 | 71 | 72 | True 73 | ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | {55BC0A1E-0595-4E35-8242-9FBF476E7557} 90 | Mvc.Bootstrap.Core 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 104 | 105 | 106 | 107 | 114 | -------------------------------------------------------------------------------- /Mvc.Bootstrap.Test/MvcHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Web; 4 | using System.Web.Mvc; 5 | using System.Web.Routing; 6 | using Moq; 7 | 8 | namespace Mvc.Bootstrap.Test 9 | { 10 | public static class MvcHelper 11 | { 12 | public const string AppPathModifier = "/$(SESSION)"; 13 | 14 | public static HtmlHelper GetHtmlHelper() 15 | { 16 | var httpcontext = GetHttpContext("/app/", null, null); 17 | var rt = new RouteCollection 18 | { 19 | new Route("{controller}/{action}/{id}", null) 20 | {Defaults = new RouteValueDictionary(new {id = "defaultid"})}, 21 | { 22 | "namedroute", 23 | new Route("named/{controller}/{action}/{id}", null) 24 | {Defaults = new RouteValueDictionary(new {id = "defaultid"})} 25 | } 26 | }; 27 | var rd = new RouteData(); 28 | rd.Values.Add("controller", "home"); 29 | rd.Values.Add("action", "oldaction"); 30 | 31 | var vdd = new ViewDataDictionary(); 32 | 33 | var viewContext = new ViewContext 34 | { 35 | HttpContext = httpcontext, 36 | RouteData = rd, 37 | ViewData = vdd 38 | }; 39 | var mockVdc = new Mock(); 40 | mockVdc.Setup(vdc => vdc.ViewData).Returns(vdd); 41 | 42 | var htmlHelper = new HtmlHelper(viewContext, mockVdc.Object, rt); 43 | return htmlHelper; 44 | } 45 | 46 | public static HtmlHelper GetHtmlHelper(ViewDataDictionary viewData) 47 | { 48 | var mockViewContext = new Mock { CallBase = true }; 49 | mockViewContext.Setup(c => c.ViewData).Returns(viewData); 50 | mockViewContext.Setup(c => c.HttpContext.Items).Returns(new Hashtable()); 51 | var container = GetViewDataContainer(viewData); 52 | return new HtmlHelper(mockViewContext.Object, container); 53 | } 54 | 55 | public static IViewDataContainer GetViewDataContainer(ViewDataDictionary viewData) 56 | { 57 | var mockContainer = new Mock(); 58 | mockContainer.Setup(c => c.ViewData).Returns(viewData); 59 | return mockContainer.Object; 60 | } 61 | 62 | public static HttpContextBase GetHttpContext(string appPath, string requestPath, string httpMethod) 63 | { 64 | return GetHttpContext(appPath, requestPath, httpMethod, Uri.UriSchemeHttp, -1); 65 | } 66 | 67 | public static HttpContextBase GetHttpContext(string appPath, string requestPath, string httpMethod, string protocol, int port) 68 | { 69 | var mockHttpContext = new Mock(); 70 | 71 | if (!String.IsNullOrEmpty(appPath)) 72 | { 73 | mockHttpContext.Setup(o => o.Request.ApplicationPath).Returns(appPath); 74 | } 75 | if (!String.IsNullOrEmpty(requestPath)) 76 | { 77 | mockHttpContext.Setup(o => o.Request.AppRelativeCurrentExecutionFilePath).Returns(requestPath); 78 | } 79 | 80 | var uri = port >= 0 ? new Uri(protocol + "://localhost" + ":" + Convert.ToString(port)) : new Uri(protocol + "://localhost"); 81 | mockHttpContext.Setup(o => o.Request.Url).Returns(uri); 82 | 83 | mockHttpContext.Setup(o => o.Request.PathInfo).Returns(String.Empty); 84 | if (!String.IsNullOrEmpty(httpMethod)) 85 | { 86 | mockHttpContext.Setup(o => o.Request.HttpMethod).Returns(httpMethod); 87 | } 88 | 89 | mockHttpContext.Setup(o => o.Session).Returns((HttpSessionStateBase)null); 90 | mockHttpContext.Setup(o => o.Response.ApplyAppPathModifier(It.IsAny())).Returns(r => AppPathModifier + r); 91 | mockHttpContext.Setup(o => o.Items).Returns(new Hashtable()); 92 | return mockHttpContext.Object; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Mvc.Bootstrap.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Mvc.Bootstrap.Test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Mvc.Bootstrap.Test")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7fe7cf80-cadd-407e-b91e-5e91dd0b95a1")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Mvc.Bootstrap.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Mvc.Bootstrap.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mvc.Bootstrap.Core", "Mvc.Bootstrap.Core\Mvc.Bootstrap.Core.csproj", "{55BC0A1E-0595-4E35-8242-9FBF476E7557}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mvc.Bootstrap.Test", "Mvc.Bootstrap.Test\Mvc.Bootstrap.Test.csproj", "{CEA9E4AB-2805-41EF-B50A-FD5A173781EF}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{138FA683-6707-4134-8808-99779B29C37B}" 9 | ProjectSection(SolutionItems) = preProject 10 | .nuget\NuGet.Config = .nuget\NuGet.Config 11 | .nuget\NuGet.exe = .nuget\NuGet.exe 12 | .nuget\NuGet.targets = .nuget\NuGet.targets 13 | EndProjectSection 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Any CPU = Debug|Any CPU 18 | Release|Any CPU = Release|Any CPU 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {55BC0A1E-0595-4E35-8242-9FBF476E7557}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {55BC0A1E-0595-4E35-8242-9FBF476E7557}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {55BC0A1E-0595-4E35-8242-9FBF476E7557}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {55BC0A1E-0595-4E35-8242-9FBF476E7557}.Release|Any CPU.Build.0 = Release|Any CPU 25 | {CEA9E4AB-2805-41EF-B50A-FD5A173781EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {CEA9E4AB-2805-41EF-B50A-FD5A173781EF}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {CEA9E4AB-2805-41EF-B50A-FD5A173781EF}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {CEA9E4AB-2805-41EF-B50A-FD5A173781EF}.Release|Any CPU.Build.0 = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(SolutionProperties) = preSolution 31 | HideSolutionNode = FALSE 32 | EndGlobalSection 33 | EndGlobal 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #MVC.Bootstrap 2 | 3 | This is a library project the extend the HtmlHelper class in ASP.Net MVC to allow you create forms for Twitter's Bootstrap CSS project. 4 | 5 | [![Stories in Ready](https://badge.waffle.io/baynezy/MVC.Bootstrap.svg?label=ready&title=Stories%20in%20Ready)](http://waffle.io/baynezy/MVC.Bootstrap) 6 | 7 | ## Build Status 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
mastermaster
developdevelop
19 | 20 | ## Documentation 21 | Fully navigable documentation available on [GitHub Pages](http://baynezy.github.io/MVC.Bootstrap/) 22 | 23 | ##Usage 24 | 25 | ### Install via NuGet 26 | 27 | [![NuGet version](https://badge.fury.io/nu/MVC.Bootstrap.Core.svg)](http://badge.fury.io/nu/MVC.Bootstrap.Core) 28 | 29 | Install-Package Mvc.Bootstrap.Core 30 | 31 | ### Make Available in Razor 32 | 33 | So you can use the extension methods in your views you need to update the web.config in your views directory to add a reference to the new .dll. 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | ### Use in your Views 49 | 50 | #### Example Model 51 | 52 | public class Item 53 | { 54 | public string Title { get; set; } 55 | public string Description { get; set; } 56 | } 57 | 58 | #### Usage in a View 59 | 60 | @model Item 61 | 62 | @using (Html.BeginForm("Index", "Home", FormMethod.Post, new {@class = "form-vertical"})) 63 | { 64 | @Html.TextBoxControlGroupFor(m => m.Title) 65 | @Html.TextAreaControlGroupFor(m => m.Description) 66 | 67 | @Html.ButtonFormAction("Submit", Buttons.Primary) 68 | } 69 | 70 | This will create an ASP.Net MVC Input Extension that works with Twitter Bootstrap 3.0. This includes validation and error messages. 71 | 72 | ##Contributing 73 | 74 | ###Pull Requests 75 | 76 | After forking the repository please create a pull request before creating the fix. This way we can talk about how the fix will be implemented. This will greatly increase your chance of your patch getting merged into the code base. 77 | 78 | ## License 79 | This project is licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0). 80 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | skip_tags: true 3 | build: 4 | publish_nuget: true 5 | verbosity: minimal 6 | environment: 7 | GithubEmail: baynezy@gmail.com 8 | GithubUsername: baynezy 9 | GithubPersonalAccessToken: 10 | secure: 9EkZYUVbHPWlMZLyUqjY79llLHc6DghntcHAodFfiMyOsIc4pbCNNEMv/lTi0SvJ 11 | deploy: 12 | - provider: NuGet 13 | api_key: 14 | secure: mqfd5QXj3a2N+D2EP9avxupQJRBJFEKT9kjF7Tipl1OCkUvPBsKjfiZMQHpnwVKq 15 | on: 16 | branch: master 17 | install: 18 | - choco install doxygen.portable 19 | after_test: 20 | - ps: C:/ProgramData/chocolatey/lib/doxygen.portable/tools/doxygen.exe doxygen.config 21 | - ps: ./pushDocumentation.ps1 $env:APPVEYOR_BUILD_FOLDER $env:GithubEmail $env:GithubUsername $env:GithubPersonalAccessToken $env:appveyor_repo_branch -------------------------------------------------------------------------------- /packages/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | 3 | !repositories.config 4 | !.gitignore -------------------------------------------------------------------------------- /packages/repositories.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /pushDocumentation.ps1: -------------------------------------------------------------------------------- 1 | param([string]$buildFolder, [string]$email, [string]$username, [string]$personalAccessToken, [string]$currentBranch) 2 | 3 | if($currentBranch -eq 'master') { 4 | Write-Host "- Set config settings...." 5 | git config --global user.email $email 6 | git config --global user.name $username 7 | git config --global push.default matching 8 | 9 | Write-Host "- Clone gh-pages branch...." 10 | cd "$($buildFolder)\..\" 11 | mkdir gh-pages 12 | git clone --quiet --branch=gh-pages https://$($username):$($personalAccessToken)@github.com/baynezy/MVC.Bootstrap.git .\gh-pages\ 13 | cd gh-pages 14 | git status 15 | 16 | Write-Host "- Clean gh-pages folder...." 17 | Get-ChildItem -Attributes !r | Remove-Item -Recurse -Force 18 | 19 | Write-Host "- Copy contents of documentation folder into gh-pages folder...." 20 | copy-item -path ..\documentation\html\* -Destination $pwd.Path -Recurse 21 | 22 | git status 23 | $thereAreChanges = git status | select-string -pattern "Changes not staged for commit:","Untracked files:" -simplematch 24 | if ($thereAreChanges -ne $null) { 25 | Write-host "- Committing changes to documentation..." 26 | git add --all 27 | git status 28 | git commit -m "skip ci - static site regeneration" 29 | git status 30 | Write-Host "- Push it...." 31 | git push --quiet 32 | Write-Host "- Pushed it" 33 | } 34 | else { 35 | Write-Host "- No changes to documentation to commit" 36 | } 37 | } 38 | else { 39 | Write-Host "- Not pushing documentation as '$currentBranch' does not match 'master'" 40 | } --------------------------------------------------------------------------------