如何从文本框中获取电子邮件

本文关键字:获取 电子邮件 文本 | 更新日期: 2023-09-27 18:07:16

EmailSender email = new EmailSender { 
                                     EmailAdresNaar = "HERE", 
                                     Onderwerp = "Test email", 
                                     Bericht = "<b>Dit is een test</b>"
                                               + "<i>cursief kan ook.</i>." 
                                    };
email.SendEmail();

我如何把一个字符串放在这里,与字符串数据某人放入这个:

<div class="editor-label">
    Email
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.Klant.email)
    @Html.ValidationMessageFor(model => model.Klant.email)
    <input type="submit" value="Verstuur" /> 
</div>

如何从文本框中获取电子邮件

[HttpPost]
public ActionResult methodName(Class model)
{
    EmailSender email = new EmailSender { 
                                         EmailAdresNaar = model.Klant.email,  
                                         Onderwerp = "Test email",  
                                         Bericht = "<b>Dit is een test</b>"
                                                   + "<i>cursief kan ook.</i>."
                                        };
    email.SendEmail();
}

你的视图应该是:

@using(Html.BeginForm("methodName"))
{
<div class="editor-label">
    Email
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.Klant.email)
    @Html.ValidationMessageFor(model => model.Klant.email)
    <input type="submit" value="Verstuur" /> 
</div>
}

也许阅读MVC的基础知识?

这样做:在视图:

@using (Html.BeginForm("MyMethod", "MyController"))
{
    <div class="editor-label">
    Email
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.Klant.email)
    @Html.ValidationMessageFor(model => model.Klant.email)
    <input type="submit" value="Verstuur" /> 
</div>
}
在控制器

public ActionResult MyMethod(ModelName model)
{
  EmailSender email = 
      new EmailSender { 
                      EmailAdresNaar = model.Klant.email,  
                      Onderwerp = "Test email",  
                      Bericht = "<b>Dit is een test</b> <i>cursief kan ook.</i>."
                    };
  email.SendEmail();
}