发送电子邮件后,清除MVC中文本字段中的数据

时间:2017-08-28 11:31:18

标签: c# asp.net asp.net-mvc asp.net-mvc-4 razor

我是MVC的初学者,在发送电子邮件后尝试清除文本字段中的数据。我已成功发送电子邮件,但发送电子邮件后数据未删除。我尝试了很多解决方案,但是我没有取得好成绩。那么,我该怎么办?

Create.cshtml

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group" id="name">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label" })
            @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control input-lg" } })
            @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
        </div>

        <div class="form-group" id="email">
            @Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label" })
            @Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control input-lg" } })
            @Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
        </div>

        <div class="form-group" id="comment">
            @Html.LabelFor(model => model.Comments, htmlAttributes: new { @class = "control-label" })
            @Html.EditorFor(model => model.Comments, new { htmlAttributes = new { @class = "form-control input-lg comments" } })
            @Html.ValidationMessageFor(model => model.Comments, "", new { @class = "text-danger" })
        </div>

        <div class="form-group">
            <input id="success" type="submit" value="Get In Touch" class="btn btn-primary btn-block btn-lg btn-login" />
            @*<a class="btn btn-primary btn-block btn-lg" onclick="SendEmail()" >click to send email</a>*@
        </div>

FeedbacksController.cs

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Id,Name,Email,Comments")] Feedback feedback)
{
    if (ModelState.IsValid)
    {
        bool result = false;
        db.Feedbacks.Add(feedback);
        db.SaveChanges();
        result = SendEmail("abc@gmail.com", "Feedback", "<p>Hi Admin,<br/>My name is "+ feedback.Name + ". <br/> E_mail ID: " + feedback.Email + "<br/><br/>" + feedback.Comments + "<br/>Kind Regards,<br/>" + feedback.Name + "</p>");

        return View( );
    }
    return View(feedback);
}

1 个答案:

答案 0 :(得分:3)

服务器端

在发送电子邮件后添加此代码

u32