lundi 9 mai 2016

Can't seem to get form values (in view) to the controller

I have 2 bits of code here.

This is my controller at the moment:

using System;
using System.Net.Mail;
using System.Web.Mvc;
using WebMatrix.Data;

namespace Best_prototype_01.Controllers
    public class RecrutaController : Controller
        public ActionResult Index()
            return View();

            protected void btnSubmit_Click(object sender, EventArgs e)
                MailMessage Msg = new MailMessage();
                // Sender e-mail address.
                Msg.From = new MailAddress(txtEmail.Text);
                // Recipient e-mail address.
                Msg.Subject = txtSubject.Text;
                Msg.Body = txtMessage.Text;
                // your remote SMTP server IP.
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "";
                smtp.Port = 587;
                smtp.Credentials = new System.Net.NetworkCredential("", "yourpassword");
                smtp.EnableSsl = true;
                //Msg = null;
                lbltxt.Text = "Thanks for Contact us";
                // Clear the textbox valuess
                txtName.Text = "";
                txtSubject.Text = "";
                txtMessage.Text = "";
                txtEmail.Text = "";
            catch (Exception ex)
                Console.WriteLine("{0} Exception caught.", ex);



And this is the view that's supposedly associated with it (the part that matters anyways):

<form id="form1"  >
        <table cellspacing="2" cellpadding="2" border="0">
            <tr><td></td><td><b>Contact Us Form</b></td></tr>
            <tr><td><b>Name</b></td><td><asp:TextBox ID="txtName"   /></td></tr>
            <tr><td><b>Email</b></td><td><asp:TextBox ID="txtEmail"   /></td></tr>
            <tr><td><b>Subject</b></td><td><asp:TextBox ID="txtSubject"   /></td></tr>
            <tr><td valign="top"><b>Message</b></td><td> <asp:TextBox ID="txtMessage" Rows="5" Columns="40" TextMode="MultiLine"   /></td></tr>
            <tr><td></td><td><asp:button ID="btnSubmit" Text="Submit"   onclick="btnSubmit_Click" CssClass="Button" /></td></tr>
            <tr><td colspan="2" style=" color:red"><asp:Label ID="lbltxt"   /></td></tr>

Can someone point me in the right direction? I have no clue what I'm doing wrong.

Aucun commentaire:

Enregistrer un commentaire