Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I try to submit email form , but the navigation is with smoothcontroll, so it is like one long page but with different sections. So in the navigation it jumps too the correct section.

I have an email section in Index.cshtml of Homecontroller, like this:
C#
<section id="contact" class="text-center">
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <section id="contact" class="text-center">
        <div class="container">
            <div class="row">
                <div class="col-md-12 wow fadeInDown" data-wow-delay="2000">
                    <h3>CONTACT Microrout.nl</h3>
                </div>
                <div class="col-md-2"></div>
                <div class="col-md-8">

                    Microrout.nl
                    <br />frederik hendriklaan 253-b
                    <br />Den Haag
                    <br />0641697144


                </div>
                <div class="col-md-2"></div>
                <hr />
                <div class="form-group">
                    @Html.LabelFor(m => m.FromName, new { @class = "col-md-3" })
                    <div class="col-md-10">
                        @Html.TextBoxFor(m => m.FromName, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.FromName)
                    </div>
                </div>
                <div class="form-group">
                    @Html.LabelFor(m => m.FromEmail, new { @class = "col-md-3 control-label" })
                    <div class="col-md-10">
                        @Html.TextBoxFor(m => m.FromEmail, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.FromEmail)
                    </div>
                </div>
                <div class="form-group">
                    @Html.LabelFor(m => m.Message, new { @class = "col-md-3 control-label" })
                    <div class="col-md-10">
                        @Html.TextAreaFor(m => m.Message, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.Message)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        <input type="submit" value="SHOOT MESSAGE" class="form-control">
                    </div>
                </div>
            </div>
        </div>
        @*<div class="google_map">
                <div id="map-canvas"></div>
            </div>*@
    </section>
}
</section>

and this is my contact method in controller Home:
C#
public ActionResult Contact()
{
    ViewBag.Message = "Your contact page.";

    return View();
}

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Contact(EmailFormModel model)
{
    string message2 = "There are a few errors";
    if (ModelState.IsValid)
    { 
        message2 = "Thanks! We'll get back to you soon.";
        var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
        var message = new MailMessage();
        message.To.Add(new MailAddress("nengelen@online.nl")); //replace with valid value
        message.Subject = "Your email subject";
        message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message);
        message.IsBodyHtml = true;
       
        using (var smtp = new SmtpClient())
        {
            await smtp.SendMailAsync(message);
            
           
        }
        ViewBag.Message = "Thank you for contact us";
        return RedirectToAction("Contact");
       
    }
    if (Request.IsAjaxRequest())
    {
        return new JsonResult { Data = new { success = true, message = message2 } };
    }

    TempData["Message"] = message2;
   
    return View(model);
}

but now this doesnt work.
Thank you
Posted
Updated 5-May-15 2:46am
v3

1 solution

Oke, I solved. I just putted:

@using (Html.BeginForm("Contact", "Home", FormMethod.Post, new { @enctype = "multipart/form-data" }))
{}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900