Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d8dbb02

Browse files
author
kadir.avci
committed
Added taghelper. Added js validation
1 parent 2e7aee9 commit d8dbb02

File tree

49 files changed

+13672
-1177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+13672
-1177
lines changed
1.35 MB
Binary file not shown.

‎.vs/VueJsTutorial/config/applicationhost.config‎

Lines changed: 920 additions & 945 deletions
Large diffs are not rendered by default.
24 KB
Binary file not shown.
0 Bytes
Binary file not shown.
-52.3 KB
Binary file not shown.

‎Common/Class1.cs‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎Common/Common.csproj‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp2.2</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<Reference Include="Microsoft.AspNetCore.Html.Abstractions">
13+
<HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.html.abstractions2円.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Html.Abstractions.dll</HintPath>
14+
</Reference>
15+
<Reference Include="Microsoft.AspNetCore.Mvc.ViewFeatures">
16+
<HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.mvc.viewfeatures2円.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.ViewFeatures.dll</HintPath>
17+
</Reference>
18+
<Reference Include="Microsoft.AspNetCore.Razor">
19+
<HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.razor2円.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Razor.dll</HintPath>
20+
</Reference>
21+
</ItemGroup>
22+
723
</Project>

‎Common/Extensions/HtmlHelpers.cs‎

Lines changed: 354 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
using Microsoft.AspNetCore.Html;
2+
using Microsoft.AspNetCore.Mvc.Rendering;
3+
using Microsoft.AspNetCore.Mvc.ViewFeatures;
4+
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
5+
using Microsoft.AspNetCore.Routing;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.ComponentModel.DataAnnotations;
9+
using System.Linq;
10+
using System.Linq.Expressions;
11+
12+
namespace Common.Extensions
13+
{
14+
public static class HtmlHelpers
15+
{
16+
public static IHtmlContent oTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> html,
17+
Expression<Func<TModel, TProperty>> expression,
18+
IDictionary<string, object> htmlAttributes = null,
19+
bool readOnly = false,
20+
bool sublist = false,
21+
bool inputGroup = false,
22+
bool isGuide = false,
23+
string guideUrl = "")
24+
{
25+
var outerDiv = new TagBuilder("div");
26+
var label = new TagBuilder("label");
27+
var labelAttributes = new Dictionary<string, object>();
28+
29+
outerDiv.AddCssClass("form-group");
30+
labelAttributes.Add("class", "control-label col-xs-12");
31+
32+
if (!sublist)
33+
{
34+
labelAttributes.Add("class", "control-label col-xs-12 col-sm-4 col-md-4 col-lg-3");
35+
}
36+
37+
var labelText = html.LabelFor(expression, labelAttributes).ToString();
38+
label.InnerHtml.AppendHtml(labelText);
39+
40+
var innerDiv = new TagBuilder("div");
41+
innerDiv.AddCssClass("col-xs-12");
42+
43+
if (!sublist)
44+
{
45+
innerDiv.AddCssClass("col-xs-12 col-sm-8 col-md-8 col-lg-9");
46+
}
47+
48+
var summaryDiv = new TagBuilder("div");
49+
var small = new TagBuilder("small");
50+
var span = new TagBuilder("span");
51+
52+
summaryDiv.AddCssClass("error-summary");
53+
summaryDiv.InnerHtml.AppendHtml(small.InnerHtml);
54+
summaryDiv.InnerHtml.AppendHtml(summaryDiv.ToString());
55+
span.AddCssClass("field-validation-valid");
56+
span.InnerHtml.AppendHtml(html.ValidationMessageFor(expression).ToString());
57+
small.InnerHtml.AppendHtml(span.InnerHtml);
58+
small.InnerHtml.AppendHtml(small.ToString());
59+
60+
if (htmlAttributes == null)
61+
{
62+
htmlAttributes = new Dictionary<string, object>();
63+
}
64+
65+
var oMetaData = ExpressionMetadataProvider.FromLambdaExpression(expression, html.ViewData, html.MetadataProvider);
66+
67+
if (oMetaData == null)
68+
{
69+
if (readOnly)
70+
{
71+
if (!htmlAttributes.ContainsKey("readonly"))
72+
{
73+
htmlAttributes.Add("readonly", "read-only");
74+
}
75+
}
76+
}
77+
else
78+
{
79+
if (!htmlAttributes.ContainsKey("placeholder"))
80+
{
81+
var fieldName = ExpressionHelper.GetExpressionText(expression);
82+
var placeholder = oMetaData.Metadata.DisplayName ?? oMetaData.Metadata.PropertyName ?? fieldName.Split('.').Last();
83+
84+
if (!string.IsNullOrWhiteSpace(placeholder))
85+
{
86+
htmlAttributes.Add("placeholder", placeholder);
87+
}
88+
89+
if (readOnly || oMetaData.Metadata.IsReadOnly)
90+
{
91+
if (!htmlAttributes.ContainsKey("readonly"))
92+
{
93+
htmlAttributes.Add("readonly", "read-only");
94+
}
95+
}
96+
}
97+
}
98+
99+
var oExpression = expression.Body as MemberExpression;
100+
101+
if (oExpression != null)
102+
{
103+
var strLengthAttribute = oExpression.Member
104+
.GetCustomAttributes(typeof(StringLengthAttribute), false)
105+
.FirstOrDefault() as StringLengthAttribute;
106+
107+
if (strLengthAttribute != null)
108+
{
109+
if (!htmlAttributes.ContainsKey("maxlength"))
110+
{
111+
htmlAttributes.Add("maxlength", strLengthAttribute.MaximumLength);
112+
}
113+
}
114+
}
115+
116+
if (htmlAttributes.ContainsKey("date"))
117+
{
118+
var inputGroupDiv = new TagBuilder("div");
119+
inputGroupDiv.AddCssClass("input-group date");
120+
121+
var spanDate = new TagBuilder("span");
122+
spanDate.AddCssClass("input-group-addon input-pe-disabled");
123+
124+
var spanIcon = new TagBuilder("span");
125+
spanIcon.AddCssClass("fa fa-calendar input-pe-disabled");
126+
127+
spanIcon.InnerHtml.AppendHtml(spanIcon.ToString());
128+
spanDate.InnerHtml.AppendHtml(spanIcon.InnerHtml);
129+
spanDate.InnerHtml.AppendHtml(spanDate.ToString());
130+
131+
inputGroupDiv.InnerHtml.AppendHtml(spanDate.InnerHtml + (html.TextBoxFor(expression, htmlAttributes)).ToString());
132+
innerDiv.InnerHtml.AppendHtml(inputGroupDiv.ToString() + summaryDiv.InnerHtml);
133+
outerDiv.InnerHtml.AppendHtml(labelText + innerDiv.ToString());
134+
}
135+
else
136+
{
137+
var sp = expression.Body.ToString().Split('.');
138+
var id = string.Empty;
139+
140+
for (int i = 0; i < sp.Length; i++)
141+
{
142+
if (i > 0)
143+
{
144+
id += sp[i];
145+
if (i < sp.Length - 1)
146+
id += "_";
147+
}
148+
}
149+
150+
innerDiv.InnerHtml.AppendHtml((inputGroup ? "<div class='input-group'>" : "") +
151+
html.TextBoxFor(expression, htmlAttributes) +
152+
(inputGroup ? "<span class='input-group-btn'><button class='btn btn-primary" + (isGuide ? " openGuide" : "") + "' type='button' " + (isGuide ? " data-href='" + guideUrl + "'" : "") + " id='groupBtn_" + id + "'><i class='fa fa-search'></i></button></span></div>" : "") +
153+
summaryDiv.InnerHtml);
154+
outerDiv.InnerHtml.AppendHtml(labelText + innerDiv.ToString());
155+
}
156+
157+
return outerDiv;
158+
}
159+
160+
public static IHtmlContent oDropDownFor<TModel, TProperty>(this HtmlHelper<TModel> html,
161+
Expression<Func<TModel, TProperty>> expression,
162+
IEnumerable<SelectListItem> list,
163+
string first,
164+
IDictionary<string, object> htmlAttributes = null,
165+
bool readOnly = false,
166+
bool sublist = false,
167+
bool isGuide = false,
168+
string guideUrl = "")
169+
{
170+
var outerDiv = new TagBuilder("div");
171+
var label = new TagBuilder("label");
172+
var labelAttributes = new Dictionary<string, object>();
173+
174+
outerDiv.AddCssClass("form-group");
175+
176+
if (!sublist)
177+
{
178+
labelAttributes.Add("class", "control-label col-xs-12 col-sm-4 col-md-4 col-lg-3");
179+
}
180+
else
181+
{
182+
labelAttributes.Add("class", "control-label col-xs-12");
183+
}
184+
185+
var labelText = html.LabelFor(expression, labelAttributes).ToString();
186+
187+
var innerDiv = new TagBuilder("div");
188+
var summaryDiv = new TagBuilder("div");
189+
var small = new TagBuilder("small");
190+
var span = new TagBuilder("span");
191+
192+
if (!sublist)
193+
{
194+
innerDiv.AddCssClass("col-xs-12 col-sm-8 col-md-8 col-lg-9");
195+
}
196+
else
197+
{
198+
innerDiv.AddCssClass("col-xs-12");
199+
}
200+
201+
label.InnerHtml.AppendHtml(labelText);
202+
summaryDiv.AddCssClass("error-summary");
203+
span.AddCssClass("field-validation-valid");
204+
span.InnerHtml.AppendHtml(html.ValidationMessageFor(expression).ToString());
205+
small.InnerHtml.AppendHtml(span.InnerHtml);
206+
small.InnerHtml.AppendHtml(small.ToString());
207+
summaryDiv.InnerHtml.AppendHtml(small.InnerHtml);
208+
summaryDiv.InnerHtml.AppendHtml(summaryDiv.ToString());
209+
210+
var dict = new RouteValueDictionary(htmlAttributes);
211+
212+
if (isGuide)
213+
{
214+
var inputGroupDiv = new TagBuilder("div");
215+
var inputGroupSpan = new TagBuilder("span");
216+
var inputGroupBtn = new TagBuilder("button");
217+
var inputGroupBtnI = new TagBuilder("i");
218+
219+
inputGroupDiv.AddCssClass("input-group");
220+
inputGroupSpan.AddCssClass("input-group-btn");
221+
inputGroupBtn.AddCssClass("btn btn-primary openGuide");
222+
inputGroupBtn.MergeAttribute("type", "button");
223+
inputGroupBtn.MergeAttribute("data-href", guideUrl);
224+
inputGroupBtnI.AddCssClass("fa fa-search");
225+
226+
inputGroupBtn.InnerHtml.AppendHtml(inputGroupBtnI.ToString());
227+
inputGroupSpan.InnerHtml.AppendHtml(inputGroupBtn.ToString());
228+
inputGroupDiv.InnerHtml.AppendHtml(html.DropDownListFor(expression, list, first, dict) + inputGroupSpan.ToString());
229+
innerDiv.InnerHtml.AppendHtml(inputGroupDiv.ToString() + summaryDiv.InnerHtml);
230+
outerDiv.InnerHtml.AppendHtml(labelText + innerDiv);
231+
}
232+
else
233+
{
234+
innerDiv.InnerHtml.AppendHtml(html.DropDownListFor(expression, list, first, dict).ToString() + summaryDiv.InnerHtml);
235+
outerDiv.InnerHtml.AppendHtml(labelText + innerDiv);
236+
}
237+
238+
return outerDiv;
239+
}
240+
241+
public static IHtmlContent oEnumDropDownFor<TModel, TProperty, TEnum>(this HtmlHelper<TModel> html,
242+
Expression<Func<TModel, TProperty>> expression,
243+
TEnum selectedValue,
244+
IEnumerable<SelectListItem> list = null,
245+
string first = "",
246+
IDictionary<string, object> htmlAttributes = null,
247+
bool readOnly = false,
248+
bool sublist = false,
249+
bool isGuide = false,
250+
string guideUrl = "")
251+
{
252+
var values = Enum.GetValues(typeof(TEnum)).Cast<TEnum>();
253+
254+
if (list == null)
255+
{
256+
list = from value in values
257+
select new SelectListItem
258+
{
259+
Text = value.ToString(),
260+
Value = Convert.ToInt32(value).ToString(),
261+
Selected = (value.Equals(selectedValue))
262+
};
263+
}
264+
265+
var outerDiv = new TagBuilder("div");
266+
outerDiv.AddCssClass("form-group");
267+
268+
var label = new TagBuilder("label");
269+
var labelAttributes = new Dictionary<string, object>();
270+
271+
if (!sublist)
272+
{
273+
labelAttributes.Add("class", "control-label col-xs-12 col-sm-4 col-md-4 col-lg-3");
274+
}
275+
else
276+
{
277+
labelAttributes.Add("class", "control-label col-xs-12");
278+
}
279+
280+
var labelText = html.LabelFor(expression, labelAttributes).ToString();
281+
label.InnerHtml.AppendHtml(labelText);
282+
283+
var innerDiv = new TagBuilder("div");
284+
285+
if (!sublist)
286+
{
287+
innerDiv.AddCssClass("col-xs-12 col-sm-8 col-md-8 col-lg-9");
288+
}
289+
else
290+
{
291+
innerDiv.AddCssClass("col-xs-12");
292+
}
293+
294+
var summaryDiv = new TagBuilder("div");
295+
var small = new TagBuilder("small");
296+
var span = new TagBuilder("span");
297+
298+
summaryDiv.AddCssClass("error-summary");
299+
span.AddCssClass("field-validation-valid");
300+
span.InnerHtml.AppendHtml(html.ValidationMessageFor(expression).ToString());
301+
small.InnerHtml.AppendHtml(span.InnerHtml);
302+
small.InnerHtml.AppendHtml(small);
303+
summaryDiv.InnerHtml.AppendHtml(small.InnerHtml);
304+
summaryDiv.InnerHtml.AppendHtml(summaryDiv);
305+
306+
var dict = new RouteValueDictionary(htmlAttributes);
307+
308+
if (isGuide)
309+
{
310+
var inputGroupDiv = new TagBuilder("div");
311+
var inputGroupSpan = new TagBuilder("span");
312+
var inputGroupBtn = new TagBuilder("button");
313+
var inputGroupBtnI = new TagBuilder("i");
314+
315+
inputGroupSpan.AddCssClass("input-group-btn");
316+
inputGroupDiv.AddCssClass("input-group");
317+
inputGroupBtn.AddCssClass("btn btn-primary openGuide");
318+
inputGroupBtn.MergeAttribute("type", "button");
319+
inputGroupBtn.MergeAttribute("data-href", guideUrl);
320+
inputGroupBtnI.AddCssClass("fa fa-search");
321+
322+
inputGroupBtn.InnerHtml.AppendHtml(inputGroupBtnI);
323+
inputGroupSpan.InnerHtml.AppendHtml(inputGroupBtn);
324+
inputGroupDiv.InnerHtml.AppendHtml(html.DropDownListFor(expression, list, first, dict).ToString() + inputGroupSpan);
325+
innerDiv.InnerHtml.AppendHtml(inputGroupDiv.ToString() + summaryDiv.InnerHtml);
326+
outerDiv.InnerHtml.AppendHtml(labelText + innerDiv);
327+
}
328+
else
329+
{
330+
innerDiv.InnerHtml.AppendHtml(html.DropDownListFor(expression, list, first, dict).ToString() + summaryDiv.InnerHtml);
331+
outerDiv.InnerHtml.AppendHtml(labelText + innerDiv);
332+
}
333+
334+
return outerDiv;
335+
}
336+
337+
public static IHtmlContent oEnumDropDownList<TEnum>(this HtmlHelper html,
338+
string name,
339+
TEnum selectedValue,
340+
IDictionary<string, object> htmlAttributes = null)
341+
{
342+
var values = Enum.GetValues(typeof(TEnum)).Cast<TEnum>();
343+
var items = from value in values
344+
select new SelectListItem
345+
{
346+
Text = value.ToString(),
347+
Value = Convert.ToInt32(value).ToString(),
348+
Selected = (value.Equals(selectedValue))
349+
};
350+
351+
return html.DropDownList(name, items, htmlAttributes);
352+
}
353+
}
354+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /