Bonjour,

La vue FormulaireModificationLivre.cshtml permet la modification des champs de la table de BDD VM_Livre.

C'est le controller Livrecontroller qui transmet à cette vue les données via le modele d'affichage VM_Livre.

Or, quand je recupère les informations de la BDD, au niveau de la vue, je ne vois pas celles du champ DateParution.

Pouvez vous me dire à quoi cela est du.Au format d'affichage, au type de données?

Merci beaucoup à vous de votre aide sur ce point.

Bien cordialement.

new_wave


modele VM_Livre

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
 
namespace e_bibliotheque_MVC.Models
{
    public class VM_Livre
    {
        [Key]
        public int Id_Livre { get; set; }
 
        [Required(ErrorMessage = "Veuillez saisir un titre")]
        [Display(Name = "Titre")]
        public string Title { get; set; }
 
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
        [Display(Name = "Date de parution")]
        public DateTime ParutionDate {get; set; }
 
        [Required(ErrorMessage = "Veuillez saisir un Id_Auteur")]
        [Column("Id_Auteur")]
        [ForeignKey(nameof(auteur))]
        public int Id_Auteur { get; set; }
 
        public VM_Auteur auteur { get; set; }
 
        [Required(ErrorMessage = "Veuillez saisir un Id_rayon")]
        [Column("Id_rayon")]
        //nameof(rayon) = nom de la navigation dépendante
        [ForeignKey(nameof(rayon))]
        public int Id_rayon { get; set; }
 
        public VM_Rayon rayon { get; set; }
 
        [Display(Name = "Photo du livre")]
        public byte[] livreImage { get; set; }
 
 
        [Display(Name = "Extension du fichier image")]
        public string livreImageType { get; set; }
 
 
 
    }
}
Vue FormulaireModificationLivre
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 
 
@model e_bibliotheque_MVC.Models.VM_Livre
 
@{
    ViewBag.Title = "FormulaireModificationLivre";
}
 
 
 
<h4>Vous allez modifier le livre suivant </h4>
 
@using (Html.BeginForm("ModifierLivre", "Livre", new { id = Model.Id_Livre }, FormMethod.Post))
{
    @Html.AntiForgeryToken()
 
    <form class="form-horizontal">
        <fieldset>
 
            <div class="form-group">
                <label class="col-lg-2 control-label">Identifiant du livre</label>
                <div class="col-lg-10">
                    <!--pour ajouter un textbox on choisit le html helper EditFor-->
                    @Html.EditorFor(model => model.Id_Livre)
 
                    <!--pour afficher les messages d'erreur de saisie -DataAnnotation de VM_Livre-->
                    @Html.ValidationMessageFor(model => model.Id_Livre)
 
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label">Titre </label>
                <div class="col-lg-10">
                    <!--pour ajouter un textbox on choisit le html helper EditFor-->
                    @Html.EditorFor(model => model.Title)
 
                    @Html.ValidationMessageFor(model => model.Title)
 
                </div>
            </div>
 
            <div class="form-group">
                <label class="col-lg-2 control-label">Date de Parution </label>
                <div class="col-lg-10">
                    <!--pour ajouter un textbox on choisit le html helper EditFor-->
                    @Html.EditorFor(model => model.ParutionDate)
 
                    @Html.ValidationMessageFor(model => model.ParutionDate)
 
                </div>
            </div>
 
 
            <div class="form-group">
                <label class="col-lg-2 control-label">Identifiant Auteur</label>
                <div class="col-lg-10">
                    <!--pour ajouter un textbox on choisit le html helper EditFor-->
                    @Html.EditorFor(model => model.Id_Auteur)
                    @Html.ValidationMessageFor(model => model.Id_Auteur)
                </div>
            </div>
 
            <div class="form-group">
                <label class="col-lg-2 control-label">Identifiant Rayon</label>
                <div class="col-lg-10">
                    <!--pour ajouter un textbox on choisit le html helper EditFor-->
                    @Html.EditorFor(model => model.Id_rayon)
                </div>
            </div>
 
            <div class="form-group">
                <div class="col-lg-10 col-lg-offset-2">
 
 
                    <!--value = action du controller-->
                    <button type="submit" class="btn btn-primary" value="ModifierLivre">Modifier un livre</button>
                    <!--retour au catalogue des livres pour modif-->
                    <button type="button" class="btn btn-primary" onclick="location.href='@Url.Action("ListerMoficationLivres","Livre")' ">Revenir au catalogue des livres</button>
 
                </div>
            </div>
        </fieldset>
    </form>
 
}
LivreController pour les actions demodification
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using e_bibliotheque_MVC.Models;
using System.Data.Entity;
 
 
namespace e_bibliotheque_MVC.Controllers
{
    public class LivreController : Controller
 
    {
        E_bibliothequeContext context = new E_bibliothequeContext();
 
 
 
 
 
 
 
        /// <summary>
        /// Affichage de la liste des livres pour modification d'un livre
        /// </summary>
        /// <returns></returns>
        public ActionResult ListerModificationLivres()
        {
 
            List<VM_Livre> livres = context.Livres.Include(li=>li.auteur).ToList();
 
            return View("ListerModificationLivres", livres);
 
        }
 
        public ActionResult FormulaireModificationLivre(int id)
        {
 
            VM_Livre livre = context.Livres.Find(id);
 
            if (livre != null)
            {
 
 
                return View("FormulaireModificationLivre", livre);
            }
 
            else
            {
                return HttpNotFound();
 
 
            }
 
        }
        /// <summary>
        /// Action de modification d'un livre
        /// <param name="livre"></param>
        /// <returns></returns>
        public ActionResult ModifierLivre(VM_Livre livre)
        {
            try
            {
                if (ModelState.IsValid)
                {
 
                    context.Entry(livre).State = EntityState.Modified;
                    context.SaveChanges();
 
                    return RedirectToAction("ListerLivres");
                }
 
                else
                {
                    return View("FormulaireModificationLivre", livre); 
 
                }
 
 
 
            }
 
            catch(Exception ex)
            {
 
                return View("FormulaireModificationLivre", livre);
 
            }
 
 
        }