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

我如何在 HERE 所在的位置放置一个字符串,并在其中放置一个字符串 dat:

<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>
4

2 回答 2

2
[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 的基础知识?

于 2013-04-03T10:39:35.787 回答
1

这样做:鉴于:

@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();
}
于 2013-04-03T10:42:55.033 回答