{"id":541,"date":"2012-02-20T19:25:59","date_gmt":"2012-02-20T17:25:59","guid":{"rendered":"http:\/\/dev.bratched.fr\/fr\/exemple-de-projet-mvc-mis-a-jour\/"},"modified":"2012-02-20T19:25:59","modified_gmt":"2012-02-20T17:25:59","slug":"exemple-de-projet-mvc-mis-a-jour","status":"publish","type":"post","link":"https:\/\/bratched.com\/fr\/2012\/02\/20\/exemple-de-projet-mvc-mis-a-jour\/","title":{"rendered":"Exemple de projet MVC (mis \u00e0 jour)"},"content":{"rendered":"<div class=\"jfdefaulttext\">J&rsquo;ai mis \u00e0 jour le <a href=\"\/en\/home\/aspnet-mvc\/62-how-we-do-aspnet-mvc.html\" target=\"_blank\" rel=\"noopener noreferrer\">projet MVC \u00e9chantillon<\/a> que j&rsquo;ai \u00e9crit pour l&rsquo;utilisation d&rsquo;ASP.NET MVC 3 et le moteur d&rsquo;affichage Razor.<\/div>\n<p>Un changement mineur, c&rsquo;est que je n&rsquo;utilise plus le FluentValidationModelValidatorProvider mais le standard. Donc j&rsquo;ai d\u00e9corer le mod\u00e8le d&rsquo;affichage avec les annotations de donn\u00e9es n\u00e9cessaires :<\/p>\n<p>&nbsp;<\/p>\n<div id=\"scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:39b2e7ac-d477-4b7b-8b06-6fee077190d6\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<pre>[Validator(typeof(UserViewModelValidator))]\npublic class UserViewModel\n{\n    public int Id { get; set; }\n\n    [DisplayName(\"First name *\")]\n    public string FirstName { get; set; }\n\n    [DisplayName(\"Last name *\")]\n    public string LastName { get; set; }\n\n    public int? Age { get; set; }\n}\n<\/pre>\n<\/div>\n<p><!--more--><\/p>\n<p>Et le validateur devient :<\/p>\n<p>&nbsp;<\/p>\n<div id=\"scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:2ea7938e-0494-4b8f-827a-6d167a2743af\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<pre>public class UserViewModelValidator : AbstractValidator\n{\n    public UserViewModelValidator()\n    {\n        RuleFor(x =&gt; x.FirstName)\n            .NotEmpty()\n            .WithMessage(\"First name is required\");\n\n        RuleFor(x =&gt; x.LastName)\n            .NotEmpty()\n            .WithMessage(\"Last name is required\");\n    }\n}\n<\/pre>\n<\/div>\n<p>Et Voici les vues correspondantes \u00e0 l&rsquo;aide de rasoir :<\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"font-size: medium\">Index.cshtml<\/span><\/strong><\/p>\n<div id=\"scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:fcf9a5ac-a3ae-4760-a115-a040122f2c7f\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<pre>@model IEnumerable\n\n@{\n    ViewBag.Title = \"Index\";\n}\n\nIndex\n@(Html\n    .Grid(Model)\n    .Columns(column =&gt; {\n        column.Custom(model =&gt; Html.Partial(\"_TableLinks\", model));\n        column.For(model =&gt; model.FirstName);\n        column.For(model =&gt; model.LastName);\n        column.For(model =&gt; model.Age);\n    })\n)\n\n\n    @(Html.ActionLink(c =&gt; c.New(), \"Create New\"))\n\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"font-size: medium\">_TableLinks.cshtml<\/span><\/strong><\/p>\n<div id=\"scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:be003ee2-842e-478a-a468-2e7a38981854\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<pre>@model SampleMvc.Web.Models.UserViewModel\n\n@(Html.ActionLink(c =&gt; c.Edit(Model.Id), \"Edit\")) |\n@(Html.ActionLink(c =&gt; c.Show(Model.Id), \"Details\")) |\n@using (Html.BeginForm(c =&gt; c.Destroy(Model.Id))) \n{\n    @Html.HttpMethodOverride(HttpVerbs.Delete)\n    \n}<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"font-size: medium\">Edit.cshtml<\/span><\/strong><\/p>\n<div id=\"scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:0233224d-b1d1-4fe0-ae8f-be72e793676d\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<pre>@model SampleMvc.Web.Models.UserViewModel\n@{\n    ViewBag.Title = \"Edit\";\n}\n\nEdit\n@using (Html.BeginForm(c =&gt; c.Update(null)))\n{\n    @Html.ValidationSummary(true)\n    @Html.HttpMethodOverride(HttpVerbs.Put)\n    @Html.HiddenFor(model =&gt; model.Id)\n    @Html.EditorForModel()\n    \n        \n    \n}\n\n    @(Html.ActionLink(c =&gt; c.Index(), \"Back to List\"))\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"font-size: medium\">New.cshtml<\/span><\/strong><\/p>\n<div id=\"scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:43c4f90f-3dad-4c7c-86ee-7c2bdaf1b3a2\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<pre>@model SampleMvc.Web.Models.UserViewModel\n\n@{\n    ViewBag.Title = \"New\";\n}\n\nNew\n@using (Html.BeginForm(c =&gt; c.Create(null))) \n{\n    @Html.ValidationSummary(true)\n    @Html.EditorForModel()\n    \n        \n    \n}\n\n    @(Html.ActionLink(c =&gt; c.Index(), \"Back to List\"))\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"font-size: medium\">Show.cshtml<\/span><\/strong><\/p>\n<div id=\"scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:79dc337e-141e-4091-9b8f-b384b57e949f\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<pre>@model SampleMvc.Web.Models.UserViewModel\n           \n@{\n    ViewBag.Title = \"Show\";\n}\n\nShow\n\n@Html.DisplayForModel()\n\n    @(Html.ActionLink(c =&gt; c.Edit(Model.Id), \"Edit\")) |\n    @(Html.ActionLink(c =&gt; c.Index(), \"Back to List\"))\n\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"font-size: medium\">Mod\u00e8le de l&rsquo;\u00e9diteur UserViewModel.cshtml<\/span><\/strong><\/p>\n<div id=\"scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:cfb6445a-cdcb-49ca-ad00-0d5a90a87b45\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<pre>@model SampleMvc.Web.Models.UserViewModel\n\n\n    Fields\n            \n    \n        @Html.LabelFor(model =&gt; model.FirstName)\n    \n    \n        @Html.EditorFor(model =&gt; model.FirstName)\n        @Html.ValidationMessageFor(model =&gt; model.FirstName)\n    \n            \n    \n        @Html.LabelFor(model =&gt; model.LastName)\n    \n    \n        @Html.EditorFor(model =&gt; model.LastName)\n        @Html.ValidationMessageFor(model =&gt; model.LastName)\n    \n            \n    \n        @Html.LabelFor(model =&gt; model.Age)\n    \n    \n        @Html.EditorFor(model =&gt; model.Age)\n        @Html.ValidationMessageFor(model =&gt; model.Age)\n    \n<\/pre>\n<\/div>\n<p><strong><span style=\"font-size: medium\">Mod\u00e8le d&rsquo;affichage UserViewModel.cshtml<\/span><\/strong><\/p>\n<div id=\"scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:f28543fb-e6df-46c8-b096-5bee71365596\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<pre>@model SampleMvc.Web.Models.UserViewModel\n\n\n    Fields\n        \n    Id\n    @Html.DisplayFor(x =&gt; x.Id)\n        \n    FirstName\n    @Html.DisplayFor(x =&gt; x.FirstName)\n        \n    LastName\n    @Html.DisplayFor(x =&gt; x.LastName)\n        \n    Age\n    @Html.DisplayFor(x =&gt; x.Age)\n\n<\/pre>\n<\/div>\n<p>Le code source est <a href=\"https:\/\/github.com\/darind\/samplemvc\" target=\"_blank\" rel=\"noopener noreferrer\">disponible sur github<\/a>.<\/p>\n<div class=\"clearfix\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>J&rsquo;ai mis \u00e0 jour le projet MVC \u00e9chantillon que j&rsquo;ai \u00e9crit pour l&rsquo;utilisation d&rsquo;ASP.NET MVC 3 et le moteur d&rsquo;affichage Razor. Un changement mineur, c&rsquo;est que je n&rsquo;utilise plus le FluentValidationModelValidatorProvider mais le standard. Donc j&rsquo;ai d\u00e9corer le mod\u00e8le d&rsquo;affichage avec les annotations de donn\u00e9es n\u00e9cessaires : &nbsp; [Validator(typeof(UserViewModelValidator))] public class UserViewModel { public int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[26,27,24],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/bratched.com\/fr\/wp-json\/wp\/v2\/posts\/541"}],"collection":[{"href":"https:\/\/bratched.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bratched.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bratched.com\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bratched.com\/fr\/wp-json\/wp\/v2\/comments?post=541"}],"version-history":[{"count":0,"href":"https:\/\/bratched.com\/fr\/wp-json\/wp\/v2\/posts\/541\/revisions"}],"wp:attachment":[{"href":"https:\/\/bratched.com\/fr\/wp-json\/wp\/v2\/media?parent=541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bratched.com\/fr\/wp-json\/wp\/v2\/categories?post=541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bratched.com\/fr\/wp-json\/wp\/v2\/tags?post=541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}