Solved

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

Posted on 2015-02-22
4
142 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
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.

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now