diff --git a/Mvc.sln b/Mvc.sln index 9fc74b2893..788e9a8325 100644 --- a/Mvc.sln +++ b/Mvc.sln @@ -98,6 +98,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "WebApiCompatShimWebSite", " EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.WebApiCompatShimTest", "test\Microsoft.AspNet.Mvc.WebApiCompatShimTest\Microsoft.AspNet.Mvc.WebApiCompatShimTest.kproj", "{5DE8E4D9-AACD-4B5F-819F-F091383FB996}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TagHelperSample.Web", "samples\TagHelperSample.Web\TagHelperSample.Web.kproj", "{2223120F-D675-40DA-8CD8-11DC14A0B2C7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -518,6 +520,16 @@ Global {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|Mixed Platforms.Build.0 = Release|Any CPU {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|x86.ActiveCfg = Release|Any CPU + {2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Debug|x86.ActiveCfg = Debug|Any CPU + {2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Release|Any CPU.Build.0 = Release|Any CPU + {2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -565,5 +577,6 @@ Global {23D30B8C-04B1-4577-A604-ED27EA1E4A0E} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E} {B2B7BC91-688E-4C1E-A71F-CE948D958DDF} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} {5DE8E4D9-AACD-4B5F-819F-F091383FB996} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1} + {2223120F-D675-40DA-8CD8-11DC14A0B2C7} = {DAAE4C74-D06F-4874-A166-33305D2643CE} EndGlobalSection EndGlobal diff --git a/samples/TagHelperSample.Web/Controllers/HomeController.cs b/samples/TagHelperSample.Web/Controllers/HomeController.cs new file mode 100644 index 0000000000..1a9188cdf9 --- /dev/null +++ b/samples/TagHelperSample.Web/Controllers/HomeController.cs @@ -0,0 +1,75 @@ + +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNet.Mvc; +using Microsoft.AspNet.Mvc.Rendering; +using TagHelperSample.Web.Models; + +namespace TagHelperSample.Web.Controllers +{ + public class HomeController : Controller + { + private static readonly IEnumerable _items = new SelectList(Enumerable.Range(7, 13)); + private static readonly Dictionary _users = new Dictionary(); + private static int _next; + + public HomeController() + { + // Unable to set ViewBag from constructor. Does this work in MVC 5.2? + ////ViewBag.Items = _items; + } + + // GET: // + public IActionResult Index() + { + return View(_users.Values); + } + + // GET: /Home/Create + public IActionResult Create() + { + ViewBag.Items = _items; + return View(); + } + + // POST: Home/Create + [HttpPost] + public IActionResult Create(User user) + { + if (user != null && ModelState.IsValid) + { + var id = _next++; + user.Id = id; + _users[id] = user; + return RedirectToAction("Index"); + } + + ViewBag.Items = _items; + return View(); + } + + // GET: /Home/Edit/5 + public IActionResult Edit(int id) + { + User user; + _users.TryGetValue(id, out user); + + ViewBag.Items = _items; + return View(user); + } + + // POST: Home/Edit/5 + [HttpPost] + public IActionResult Edit(int id, User user) + { + if (user != null && id == user.Id && _users.ContainsKey(id) && ModelState.IsValid) + { + _users[id] = user; + return RedirectToAction("Index"); + } + + ViewBag.Items = _items; + return View(); + } + } +} diff --git a/samples/TagHelperSample.Web/Models/User.cs b/samples/TagHelperSample.Web/Models/User.cs new file mode 100644 index 0000000000..eb1b574a67 --- /dev/null +++ b/samples/TagHelperSample.Web/Models/User.cs @@ -0,0 +1,18 @@ + +using System; + +namespace TagHelperSample.Web.Models +{ + public class User + { + public int Id { get; set; } + + public string Name { get; set; } + + public string Blurb { get; set; } + + public DateTimeOffset DateOfBirth { get; set; } + + public int YearsEmployeed { get; set; } + } +} \ No newline at end of file diff --git a/samples/TagHelperSample.Web/Startup.cs b/samples/TagHelperSample.Web/Startup.cs new file mode 100644 index 0000000000..bf2cd2d968 --- /dev/null +++ b/samples/TagHelperSample.Web/Startup.cs @@ -0,0 +1,15 @@ + +using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; + +namespace TagHelperSample.Web +{ + public class Startup + { + public void Configure(IApplicationBuilder app) + { + app.UseServices(services => services.AddMvc()); + app.UseMvc(); + } + } +} diff --git a/samples/TagHelperSample.Web/TagHelperSample.Web.kproj b/samples/TagHelperSample.Web/TagHelperSample.Web.kproj new file mode 100644 index 0000000000..3d932a6a8f --- /dev/null +++ b/samples/TagHelperSample.Web/TagHelperSample.Web.kproj @@ -0,0 +1,18 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 2223120f-d675-40da-8cd8-11dc14a0b2c7 + Web + TagHelperSample.Web + + + 2.0 + 31726 + + + \ No newline at end of file diff --git a/samples/TagHelperSample.Web/Views/Home/Create.cshtml b/samples/TagHelperSample.Web/Views/Home/Create.cshtml new file mode 100644 index 0000000000..63dd93cf61 --- /dev/null +++ b/samples/TagHelperSample.Web/Views/Home/Create.cshtml @@ -0,0 +1,89 @@ + +@using TagHelperSample.Web.Models +@model User + +

Create

+ +@* anti-forgery is on by default *@ +@* form will special-case anything that looks like a URI i.e. contains a '/' or doesn't match an action *@ +
+
+ @* validation summary tag helper will target just
elements and append the list of errors *@ + @* - i.e. this helper, like + +
+ @* no special-case for the "for" attribute; may eventually need to opt out on per-element basis here and in *@ +
+
+
+
+
+ + + diff --git a/samples/TagHelperSample.Web/Views/Home/Edit.cshtml b/samples/TagHelperSample.Web/Views/Home/Edit.cshtml new file mode 100644 index 0000000000..15003e6c88 --- /dev/null +++ b/samples/TagHelperSample.Web/Views/Home/Edit.cshtml @@ -0,0 +1,61 @@ + +@using TagHelperSample.Web.Models +@model User + +

Edit

+ +
+
+
+ + +
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+ + + diff --git a/samples/TagHelperSample.Web/Views/Home/Index.cshtml b/samples/TagHelperSample.Web/Views/Home/Index.cshtml new file mode 100644 index 0000000000..f07d0bcf76 --- /dev/null +++ b/samples/TagHelperSample.Web/Views/Home/Index.cshtml @@ -0,0 +1,35 @@ + +@using TagHelperSample.Web.Models +@model IEnumerable + +

Index

+

+ Create New +

+ +@if (Model != null && Model.Count() != 0) +{ +
+ @foreach (var item in Model) + { +
+
+
+
+
+
+
+