0

I have create a WebGrid in ASP.NET MVC.

In this WebGrid I show two links:

webGrid.Column("", format: item => Html.ActionLink("PDF", "ExportPDF", new { id = item.sID }, new { target = "_blank" })),
webGrid.Column("", format: item => Html.ActionLink("E-mail", "SendEmail", new { id = item.sID }, new { target = "_blank" })),

The first link get the item.sID to controller for export file PDF

public void ExportPDF(int id)
{
    // code
}

The second link open a new View with form for send an email message

@using (@Html.BeginForm("Email", "Home", FormMethod.Post))
{
    @Html.AntiForgeryToken()
    <div>
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="row">
            <div class="col-md-3">
                <div class="form-group">
                    @Html.LabelFor(model => model.To, "To", htmlAttributes: new { @Class = "Mytextarea2" })
                    @Html.TextBoxFor(m => m.To, new { @Class = "Mytextarea2", placeholder = "To" })
                    @Html.ValidationMessageFor(m => m.To, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>
}

I can't go retrieve and sending the value of item.sID a new View with form for send an email message

[HttpPost]
public ActionResult SendEmail(int id)
{
    return View();
}

the question is

How to do get the value of item.sID from the View (with the form for sending the email message) to pass to ActionResult Email(PersonModel model) for export pdf with item.sID value?

[HttpPost]
public ActionResult Email(PersonModel model)
{
    string from = System.Web.HttpContext.Current.Session["UserEmail"].ToString();
    using (MailMessage mail = new MailMessage(from, model.To))
    {
        mail.Subject = model.Subject;
        mail.Body = model.Body;
        mail.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "xxxx";
        smtp.Port = 25;
        smtp.Send(mail);
        ViewBag.Message = "Email";
        return View("Email", model);
    }
}

0 Answers0