Solved

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

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video teaches users how to migrate an existing Wordpress website to a new domain.
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.

706 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

19 Experts available now in Live!

Get 1:1 Help Now