Add form to subscribe the newsletter in C #

-2

Live. I'm developing a website in C #, asp.net with visual studio feature. I would like to put a small form where the site viewer places your email to subscribe to a newsletter. I have already researched ways to do this but I have not found any correct ones. I do not know how it works, if it needs resources to other tools, etc.

Something like that - > (doneonWIX.com)

Codeusedtoenforcethisoperation:

MailMessagemail=newMailMessage();SmtpClientclient=newSmtpClient();client.Port=25;client.DeliveryMethod=SmtpDeliveryMethod.Network;client.UseDefaultCredentials=false;client.Host="smtp.gmail.com";
mail.To = "[email protected]"; //
mail.From = "[email protected]";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
    
asked by anonymous 17.05.2018 / 12:44

1 answer

0

See if that's what you want:

Template

public class Pessoa
{

    // No seu caso, acho que esse campo é opcional.
    public int Id { get; set; }

    [Required(ErrorMessage = "Campo Obrigatório")]
    public string Name { get; set; }

    [Required(ErrorMessage = "Campo Obrigatório")]
    public string Email { get; set; }
}

Actions within the Controller

[HttpGet]
public ActionResult Index()
{
    return View();
}

[HttpPost]
public ActionResult Index(Pessoa pessoa)
{
    if (ModelState.IsValid)
    {
        // Grava no banco ou o que quiser que seja feito.
    }

    return View();
}

View

@model SeuProjeto.Model.Pessoa

@using (Html.BeginForm("Index", "SeuController", FormMethod.Post))
{
<div class="form-group">
    <label>Nome</label>
    <input type="text" class="form-control" placeholder="Digite o nome">
</div>

<div class="form-group">
    <label>Email</label>
    <input type="email" class="form-control" placeholder="Digite o email">
</div>

<button type="submit" class="btn btn-primary">Enviar</button>
}
    
17.05.2018 / 15:45