Quellcode durchsuchen

NEW Ajout d'un Helper pour DescriptionFor

julien.legrand vor 9 Jahren
Ursprung
Commit
3171e279ea

+ 1 - 0
CD67.ModeleMVC.MVC/CD67.ModeleMVC.MVC.csproj

@@ -147,6 +147,7 @@
     <Compile Include="Global.asax.cs">
       <DependentUpon>Global.asax</DependentUpon>
     </Compile>
+    <Compile Include="Internal\MvcHtmlHelpers.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>

+ 17 - 0
CD67.ModeleMVC.MVC/Internal/MvcHtmlHelpers.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Linq.Expressions;
+using System.Web.Mvc;
+
+namespace CD67.ModeleMVC.MVC
+{
+    public static class MvcHtmlHelpers
+    {
+        public static MvcHtmlString DescriptionFor<TModel, TValue>(this HtmlHelper<TModel> self, Expression<Func<TModel, TValue>> expression)
+        {
+            var metadata = ModelMetadata.FromLambdaExpression(expression, self.ViewData);
+            var description = metadata.Description;
+
+            return MvcHtmlString.Create(string.Format(@"<span>{0}</span>", description));
+        }
+    }
+}

+ 2 - 0
CD67.ModeleMVC.MVC/Views/VIKINGS/Create.cshtml

@@ -55,6 +55,7 @@
             <div class="col-md-10">
                 @Html.EditorFor(model => model.alwaysYes, new { htmlAttributes = new { @class = "form-control" } })
                 @Html.ValidationMessageFor(model => model.alwaysYes, "", new { @class = "text-danger" })
+                @Html.DescriptionFor(model=>model.alwaysYes)
             </div>
         </div>
 
@@ -63,6 +64,7 @@
             <div class="col-md-10">
                 @Html.EditorFor(model => model.alwaysNo, new { htmlAttributes = new { @class = "form-control" } })
                 @Html.ValidationMessageFor(model => model.alwaysNo, "", new { @class = "text-danger" })
+                @Html.DescriptionFor(model => model.alwaysNo)
             </div>
         </div>
 

+ 2 - 0
CD67.ModeleMVC.MVC/Views/VIKINGS/Edit.cshtml

@@ -47,6 +47,7 @@
             <div class="col-md-10">
                 @Html.EditorFor(model => model.alwaysYes, new { htmlAttributes = new { @class = "form-control" } })
                 @Html.ValidationMessageFor(model => model.alwaysYes, "", new { @class = "text-danger" })
+                @Html.DescriptionFor(model => model.alwaysYes)
             </div>
         </div>
 
@@ -55,6 +56,7 @@
             <div class="col-md-10">
                 @Html.EditorFor(model => model.alwaysNo, new { htmlAttributes = new { @class = "form-control" } })
                 @Html.ValidationMessageFor(model => model.alwaysNo, "", new { @class = "text-danger" })
+                @Html.DescriptionFor(model => model.alwaysNo)
             </div>
         </div>
 

+ 2 - 0
README.md

@@ -74,6 +74,8 @@ La configuration de ceci se trouve dans ce fichier : "App_Start\BundleConfig.cs"
 Les Glyphicons Bootstrap sont ici : http://getbootstrap.com/components/#glyphicons
 Et les icônes FontAwesome là : http://fontawesome.io/icons/
 
+Le dossier "Internal" contient du code permettant l'ajout de la commande "@Html.DescriptionFor" dans les vues.
+
 
 # CD67.ModeleMVC.Tests
 Projet le plus important de la solution :)