Bonjour tous le monde,

Je suis entrain de développer une application ASP MVC 3, elle est liée à une DLL (comme reference) qui comporte un ensemble de fonctions pour ajouter, supprimer, modifier des champs dans une base SQL SERVER.

Mon premier essai est d'ajouter un nouveau utilisateur dans la base (table User).

J'ai crée donc la méthode addUser dans le controlleur mais je n'arrive pas à l'appeler dans mon view.

Que dois je faire ?

Merci de m'aider

Voici le fichier AccountContoller.cs (le controleur) :
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
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Web.UI;
using Gamme;
using System.Text.RegularExpressions;
 
 
 
    [HandleError]
    public class AccountController : Controller
    {
 
 
        /// <summary>
        ///  This method is a custom design gallery method
        /// </summary>
        /// <returns></returns>
        public ActionResult LogonPartial()
        {
            return View();
        }
 
        public ActionResult AddUser()
 
        {
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return View();
 
        }
 
 
        // This constructor is used by the MVC framework to instantiate the controller using
        // the default forms authentication and membership providers.
 
        public AccountController()
            : this(null, null)
        {
        }
public AccountController(IFormsAuthentication formsAuth, IMembershipService service)
        {
            FormsAuth = formsAuth ?? new FormsAuthenticationService();
            MembershipService = service ?? new AccountMembershipService();
        }
[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult AddUser(string userName, string nom, string password, string type)
        {
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
 
            if (ValidateAjout(userName, nom, password, type))
            {
                Gamme.UserManager um = new UserManager("SWEET-DE396641E\\SQLEXPRESS");
                um.addUser("hhhh", "ggggg", "hhhhjk", "Admin");
            }
 
            return View();
}
private bool ValidateAjout(string userName, string nom, string password, string type)
        {
            if (String.IsNullOrEmpty(userName))
            {
                ModelState.AddModelError("username", "Vous devez spécifier un nom d'utilisateur !");
            }
            if (String.IsNullOrEmpty(nom))
            {
                ModelState.AddModelError("nom", "Vous devez spécifier un nom !");
            }
 
            if (password == null || password.Length < MembershipService.MinPasswordLength)
            {
                ModelState.AddModelError("password",
                    String.Format(CultureInfo.CurrentCulture,
                         "Vous devez spécifier un mot de passe de {0} ou plus !",
                         MembershipService.MinPasswordLength));
            }
            if (String.IsNullOrEmpty(type))
            {
                ModelState.AddModelError("type", "Vous devez spécifier un type !");
            }
 
            return ModelState.IsValid;
        }
}
et voila le code de la page addUser.aspx (le view) :
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
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="AccountController" %>
<script runat="server">
 
    protected void Button1_Click(object sender, EventArgs e)
    {
 
    }
</script>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <form id="form1" runat="server">
    <h2><%= Html.Encode(ViewData["Message"]) %> </h2>
 
    <div style="color:Gray">
<h2>Ajouter un nouveau utilisateur</h2>
 
<p>
    Utilisez le formulaire ci-dessous pour créer un nouveau compte.
</p>
<p>
    Les mots de passe sont nécessaires pour avoir un minimum de <%= Membership.MinRequiredPasswordLength%> caractères.
</p>
 
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
 
<%= Html.ValidationSummary() %>
 
     <% using (Html.BeginForm())
        {%>
 
    <div>
        <fieldset class="fields">
            <legend>Information de Compte</legend>
 
            <div class="editor-label">
               <label for="m => m.UserName">Matricule :</label>
                <%= Html.TextBox("m => m.UserName")%>
               <%= Html.ValidationMessage("m => m.UserName", "*")%>
 
                       </div>
 
              <div class="editor-label">
               <label for="m => m.Name">Nom  :</label>
                <%= Html.TextBox("m => m.Name")%>
               <%= Html.ValidationMessage("m => m.Name", "*")%>
 
                </div>
 
                       <div class="editor-label">
               <label for="m => m.Password">Mot de Passe :</label>
                <%= Html.TextBox("m => m.Password")%>
               <%= Html.ValidationMessage("m => m.Password", "*")%>
 
                       </div>
 
                        <div class="editor-label">
               <label for="m => m.ConfirmPassword">Confirmez le mot de passe :</label>
                <%= Html.TextBox("m => m.ConfirmPassword")%>
               <%= Html.ValidationMessage("m => m.ConfirmPassword", "*")%>
 
                       </div>
 
                       <div class="editor-label">
               <label for="m => m.Type">Type :</label>
                <%= Html.TextBox("m => m.Type")%>
               <%= Html.ValidationMessage("m => m.Type", "*")%>
 
                       </div>
 
             <p>
 
                 <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"
                     Width="48px" />
            </p>
        </fieldset>
    </div>
<%}%>
</div>
 
    </form>
 
</asp:Content>
Sachant QUE :

Mon DLL est appelé 'Gamme'

le language utilisé c'est le C#