?
Solved

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

Posted on 2015-02-22
4
Medium Priority
?
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
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…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

719 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