Solved

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

Posted on 2015-02-22
4
148 Views
Last Modified: 2015-02-23
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

0
Comment
Question by:TransBind
  • 2
4 Comments
 
LVL 7

Author Comment

by:TransBind
ID: 40623943
Contact Us form is not posting back from the view to the controller
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 250 total points
ID: 40625871
I see a controller method that has the HttpPost attribute, so if you are getting an HTTP 404 error, then my guess would be that it can't find the correct route.
0
 
LVL 25

Accepted Solution

by:
apeter earned 250 total points
ID: 40626987
Please check the developer tools for the browser. Go to network tab and try to find what call is made from client to server and parameters/values going fine.
0
 
LVL 7

Author Comment

by:TransBind
ID: 40627041
Thank you both. I am accepting multiple solutions as your answers guided me to a solution.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question