Link to home
Start Free TrialLog in
Avatar of TransBind
TransBind

asked on

MVC C# - Contact Us form is not posting back from the view to the controller

Contact Us form is not posting back from the view to the controller

I receive the following error when I click "Send Email" button:

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Most likely causes:
The directory or file specified does not exist on the Web server.
The URL contains a typographical error.
A custom filter or module, such as URLScan, restricts access to the file.

View:
@model Solution.Models.ContactUsModels
@{
    ViewBag.Title = "Contact Us | Solution Tutoring";
    ViewBag.MetaDescription = "Contact Us | Solution Tutoring";
}
<div id="content" style="width: 700px;">
    <div class="contentdecor">
        <h2 class="title">Contact us</h2>
        <div class="entry">
            <p>Before contacting us please review our <strong><a href="how-it-works">how it works</a></strong> section. Many frequently asked questions are addressed on the help pages.</p>

            <p class="entryinfo">Please use the form below to send us an email with any questions or comments. This is the best way to contact us.</p>
        </div>

        <div class="generalform">
            @using (Html.BeginForm("ContactUs", "Contact_Us", FormMethod.Post, new { enctype = "multipart/form-data" }))
            {
                @Html.ValidationSummary(true)
                <div class="editor-label">
                    @Html.LabelFor(model => model.Name, "Name:")
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Name)
                    @Html.ValidationMessageFor(model => model.Name)
                </div>

                <div class="editor-label">
                    @Html.LabelFor(model => model.Email, "Email:")
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Email)
                    @Html.ValidationMessageFor(model => model.Email)
                </div>

                <div class="editor-label">
                    @Html.LabelFor(model => model.Message, "Message:")
                </div>
                <div class="editor-field">
                    @Html.TextAreaFor(model => model.Message)
                    @Html.ValidationMessageFor(model => model.Message)
                </div>
            
            <p>
                <input class="submit" type="submit" value="Send Email" />
            </p>

            }
        </div>
    </div>
</div>

Open in new window


Model:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace Solution.Models
{
    public class ContactUsModels
    {
        [Required(ErrorMessage = "Name is required")]
        public string Name { get; set; }

        [Required(ErrorMessage = "Email is required")]
        public string Email { get; set; }

        [Required(ErrorMessage = "Message is required")]
        public string Message { get; set; }
    }
}

Open in new window


Controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Solution.Models;

namespace Solution.Controllers
{

    public class Contact_UsController : Controller
    {
        //
        // GET: /Contact-Us/
        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult ContactUs(ContactUsModels contactContent)
        {
            if (ModelState.IsValid)
            {
            }
            return View(contactContent);
        }

    }
}

Open in new window

Avatar of TransBind
TransBind

ASKER

Contact Us form is not posting back from the view to the controller
SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you both. I am accepting multiple solutions as your answers guided me to a solution.