Désolé de demander cela, mais je débute vraiment en ASP.NET MVC, et j'ai déjà du mal à comprendre l'ASP tout court ^^
J'ai effectivement placé mon formulaire sur ma page .aspx qui est une vue possédant une Page Master. Voici le bouton de Submit :
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
Ce que je ne comprends pas en réalité, c'est que j'ai un controleur qui controle mes vues, qui commence par :
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
| using System.Xml;
using System.Data;
using System.Configuration;
using System.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Projet.Controllers
{
public class ProjetController : Controller
{
// GET: /ProjetHome/
public ActionResult Index()
{
return View();
}
public ActionResult Team()
{
return View();
}
public ActionResult Contact()
{
return View();
}
...
} |
Ce que je ne comprends pas, c'est où on peut gérer les résultats de mon formulaire. Je ne comprends pas où insérer :
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
| public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BindData();
}
protected void Button1_Click(object sender, EventArgs e)
{
// Open the XML doc
System.Xml.XmlDocument myXmlDocument = new System.Xml.XmlDocument();
myXmlDocument.Load(Server.MapPath("guestbook.xml"));
System.Xml.XmlNode myXmlNode = myXmlDocument.DocumentElement.FirstChild;
// Create new XML element and populate its attributes
System.Xml.XmlElement myXmlElement = myXmlDocument.CreateElement("entry");
myXmlElement.SetAttribute("name", Server.HtmlEncode(txtName.Text));
myXmlElement.SetAttribute("email", Server.HtmlEncode(txtEmail.Text));
myXmlElement.SetAttribute("location", Server.HtmlEncode(txtLocation.Text));
myXmlElement.SetAttribute("date", DateTime.Now.ToString());
myXmlElement.InnerText = Server.HtmlEncode(txtComments.Text);
// Insert data into the XML doc and save
myXmlDocument.DocumentElement.InsertBefore(myXmlElement, myXmlNode);
myXmlDocument.Save(Server.MapPath("guestbook.xml"));
// Re-bind data since the doc has been added to
BindData();
}
void BindData()
{
XmlTextReader myXmlReader = new XmlTextReader(Server.MapPath("guestbook.xml"));
DataSet myDataSet = new DataSet();
myDataSet.ReadXml(myXmlReader);
myXmlReader.Close();
Guestbook.DataSource = myDataSet.Tables[0];
Guestbook.DataBind();
}
} |
Merci d'avance pour votre aide
Partager