{"id":1085,"date":"2012-09-23T05:24:51","date_gmt":"2012-09-23T05:24:51","guid":{"rendered":"http:\/\/nestor.nestasoft.fr\/?p=1085"},"modified":"2012-11-17T04:24:41","modified_gmt":"2012-11-17T04:24:41","slug":"asp-net-mvc-4-quatrime-partie-ajout-dune-vue","status":"publish","type":"post","link":"https:\/\/nestasoft.fr\/?p=1085","title":{"rendered":"ASP.NET MVC 4 [Quatri\u00e8me partie] : Ajout d&rsquo;une vue"},"content":{"rendered":"<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/ApresCreatyionAdherent.PNG\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 10px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\"  title=\"Vue2\" border=\"0\" alt=\"Vue2\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/ApresCreatyionAdherent.PNG\" width=\"600\" height=\"225\" \/><\/a><\/p>\n<ol>\n<li><strong><font color=\"#4f81bd\"><a href=\"http:\/\/nestor.nestasoft.fr\/?p=1012\" target=\"_blank\">ASP.NET MVC 4 [Premi\u00e8re partie]&#160;&#160; : Introduction<\/a><\/font><\/strong> <\/li>\n<li><strong><font color=\"#4f81bd\"><a href=\"http:\/\/nestor.nestasoft.fr\/?p=1059\" target=\"_blank\">ASP.NET MVC 4 [Deuxi\u00e8me partie]&#160; : Ajout d\u2019un model<\/a><\/font> <\/strong><\/li>\n<li><font color=\"#4f81bd\"><strong><a href=\"http:\/\/nestor.nestasoft.fr\/?p=1067\" target=\"_blank\">ASP.NET MVC 4 [Troisi\u00e8me partie]&#160; : Ajout d\u2019un contr\u00f4leur<\/a><\/strong><\/font> <\/li>\n<li><font color=\"#4f81bd\"><strong>ASP.NET MVC 4 [Quatri\u00e8me partie] : Ajout d\u2019une vue<\/strong><\/font> <\/li>\n<li><font color=\"#4f81bd\">ASP.NET MVC 4 [Cinqui\u00e8me partie] : Page Inspector<\/font> <\/li>\n<li><font color=\"#4f81bd\">ASP.NET MVC 4 [Sixi\u00e8me partie]&#160;&#160;&#160;&#160;&#160; : Razor ou ASPX<\/font> <\/li>\n<li><font color=\"#4f81bd\">ASP.NET MVC 4 [Septi\u00e8me partie]&#160;&#160; : Conclusion<\/font> <\/li>\n<\/ol>\n<p>Petit rappel, La <b>vue<\/b> : affiche le contenu envoy\u00e9 par le contr\u00f4leur dans un fureteur (navigateur). Utilis\u00e9 par l\u2019application pour g\u00e9n\u00e9rer dynamiquement des r\u00e9ponses HTML.<\/p>\n<p><font color=\"#000000\"><strong>Modification du fichier<\/strong> <em>_Layout.cshtml<\/em><\/font><\/p>\n<p>Nous allons modifier le contenu du fichier _Layout.cshtml qui se trouve dans le dossier \u201cViews\/Shared\u201d.<\/p>\n<p>&#160;<\/p>\n<p><!--more--><\/p>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/OuvertureFichier.PNG\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/OuvertureFichier.PNG\" width=\"510\" height=\"480\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<p><em><strong>Titre de la page :<\/strong> <\/em><\/p>\n<pre class=\"brush:html\">&lt;title&gt;@ViewBag.Title - CSMvc4 en action&lt;\/title&gt;<\/pre>\n<p>La ViewBag est un objet dynamique. Cet objet ne poss\u00e8de aucune propri\u00e9t\u00e9 d\u00e9fini, et ce jusqu\u2019\u00e0 ce que vous lui fournissez des donn\u00e9es. Je vous montrerai une petite d\u00e9mo dans la suite.<\/p>\n<p>&#160;<\/p>\n<p><em><strong>En t\u00eate de notre page :<\/strong><\/em><\/p>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/EntetePage.PNG\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/EntetePage.PNG\" width=\"600\" height=\"50\" \/><\/a><\/p>\n<p>\n  <br \/><em>ActionLink<\/em> est une m\u00e9thode qui retourne l\u2019\u00e9l\u00e9ment d\u2019encrage qui contient le chemin d\u2019acc\u00e8s virtuel de l\u2019action sp\u00e9cifi\u00e9e.<\/p>\n<p>Le premier param\u00e8tre (ici CSMvc4 en action) est le lien.<\/p>\n<p>Le second (ici Index) est l\u2019action.<\/p>\n<p>Le troisi\u00e8me (ici Home) est le contr\u00f4leur.<\/p>\n<p>&#160;<\/p>\n<p>Ayant fait le tour de ce fichier, modifions rapidement (pas de code ici) les 3 fichiers qui se trouvent dans <em>Views\/Home<\/em>, ainsi que le fichier <em>HomeControleur.cs<\/em><\/p>\n<p><em><\/em><\/p>\n<p>Page apr\u00e8s modification : <\/p>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/PageFinal.PNG\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/PageFinal.PNG\" width=\"600\" height=\"336\" \/><\/a><\/p>\n<p><em><strong><\/strong><\/em><\/p>\n<p><em><strong>Ajout d\u2019une vue et D\u00e9mo sur la ViewBag<\/strong><\/em><\/p>\n<p><strong><em><\/em><\/strong><\/p>\n<p>Pour ajouter une vue, positionner le curseur sur une action et faites un click droit, puis Ajouter une vue.<\/p>\n<p>&#160;<\/p>\n<p><em><strong>Pour la d\u00e9mo de la ViewBag<\/strong><\/em><\/p>\n<p>Ajoutons une action dans le contr\u00f4leur : <\/p>\n<pre class=\"brush:csharp\">public ActionResult ViewBagDemo(string name = &quot;Nesta&quot;, string year = &quot;2002&quot;) { ViewBag.Message = &quot;D\u00e9montration de la ViewBag par &quot; + name; ViewBag.Annee = year; return View(); } <\/pre>\n<p>&#160;<\/p>\n<p>Cr\u00e9er&#160; la vue ViewBagDemo.cshml<\/p>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/AjoutDeVue.PNG\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/AjoutDeVue.PNG\" width=\"600\" height=\"383\" \/><\/a><\/p>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/cshtmlViewBagDemo.PNG\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/cshtmlViewBagDemo.PNG\" width=\"329\" height=\"190\" \/><\/a><\/p>\n<p>\n  <br \/><em><strong>R\u00e9sultat :<\/strong><\/em> <\/p>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/Resultat.PNG\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/Resultat.PNG\" width=\"550\" height=\"354\" \/><\/a><\/p>\n<p><em><strong><\/strong><\/em><\/p>\n<p><em><strong>Voici \u00e0 quoi ressemble notre application :<\/strong><\/em> <\/p>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/ApresCreatyionAdherent.PNG\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/ApresCreatyionAdherent.PNG\" width=\"600\" height=\"203\" \/><\/a><\/p>\n<p>&lt;image&gt;<\/p>\n<p>&#160;<\/p>\n<p><em><strong><font color=\"#008000\">Cr\u00e9ation d\u2019un adh\u00e9rent<\/font><\/strong><\/em><\/p>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/CreationAdherent.PNG\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/CreationAdherent.PNG\" width=\"477\" height=\"752\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<p><em><strong><font color=\"#008000\">Validation des champs<\/font><\/strong><\/em><\/p>\n<p>Si une mauvaise date est saisie par exemple, un message de validation est affich\u00e9e. Nous verrons plus loin, comment ajouter des validations \u00e0 notre model. <\/p>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/ValidationDeChamp.PNG\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/ValidationDeChamp.PNG\" width=\"600\" height=\"437\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<p><strong><em><font color=\"#008000\">\u00c9diter un adh\u00e9rent<\/font><\/em><\/strong><\/p>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/EditionAdherent.PNG\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/EditionAdherent.PNG\" width=\"489\" height=\"453\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<p><em><strong><font color=\"#008000\">Supprimer un Adh\u00e9rent<\/font><\/strong><\/em><\/p>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/ConfirmationDeSuppresion.PNG\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/ConfirmationDeSuppresion.PNG\" width=\"563\" height=\"523\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<p><em><strong><font color=\"#008000\">D\u00e9tail d\u2019un adh\u00e9rent<\/font><\/strong><\/em><\/p>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/DetailAdherent.PNG\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/09\/DetailAdherent.PNG\" width=\"542\" height=\"457\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<p>Be connected!<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1085\" class=\"pvc_stats all  \" data-element-id=\"1085\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/nestasoft.fr\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>ASP.NET MVC 4 [Premi\u00e8re partie]&#160;&#160; : Introduction ASP.NET MVC 4 [Deuxi\u00e8me partie]&#160; : Ajout d\u2019un model ASP.NET MVC 4 [Troisi\u00e8me partie]&#160; : Ajout d\u2019un contr\u00f4leur ASP.NET MVC 4 [Quatri\u00e8me partie] : Ajout d\u2019une vue ASP.NET MVC 4 [Cinqui\u00e8me partie] : Page Inspector ASP.NET MVC 4 [Sixi\u00e8me partie]&#160;&#160;&#160;&#160;&#160; : Razor ou ASPX ASP.NET MVC 4 [Septi\u00e8me [&hellip;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1085\" class=\"pvc_stats all  \" data-element-id=\"1085\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/nestasoft.fr\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":1181,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-1085","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts\/1085","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1085"}],"version-history":[{"count":12,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts\/1085\/revisions"}],"predecessor-version":[{"id":1094,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts\/1085\/revisions\/1094"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/media\/1181"}],"wp:attachment":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}