Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MVC 3 Submit Button not working properly

Posted on 2012-12-25
12
Medium Priority
?
1,305 Views
Last Modified: 2013-01-01
I'm using mvc 3 (C#), I have a contact form used for sending emails.  However the submit button does not work properly.

//view/home/contact.cshtml

@using (Html.BeginForm())
   {
    <div id="divContact">      
   <table>
    <tr>
        <td>
            @Html.TextArea("txtComment", "")            
        </td>
    </tr>
    <tr>
        <td>
            <input id="btnContactSubmit" name="btnSubmit" type="submit" value="Send" />
        </td>
    </tr>
   </table>
   </div>
   }

//HomeController

 [HttpPost]
        public ActionResult Contact(string email, string subject, string body)
        {
            try
            {
                WebMail.SmtpServer = "smtp info goes here";
                WebMail.Send(email, subject, body, email);
                return RedirectToAction("Confirmation", "Email");
            }
            catch (Exception)
            {
                return RedirectToAction("SendError", "Email");
            }
        }


This works fine on my local host, however, when I upload it to godaddy, the submit does not seem to do anything when pressed.
0
Comment
Question by:mmsi
[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
  • 6
  • 6
12 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38720482
Your POST action expects three parameters, but I don't see in your view where you are submitting three fields. Is this view supposed to post back to this particular POST action?
0
 

Author Comment

by:mmsi
ID: 38720503
Yes, this view is posting back to the Post action.  I was thinking that during the post the form fields were being passed.  If this is wrong, why does it work on my local host?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38720521
When you say that it works on localhost, do you actually have values in the email, subject, and body variables when the page posts bac?
0
Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 

Author Comment

by:mmsi
ID: 38720998
To answer your question Yes, however, on the local host,  my smpt server denies access because I don't have permission to send emails.

So, for testing purposes, i commented out the webmail code.   When I press the submit button on the local host it takes me to:
http://localhost:10016/Email/Confirmation

When I run it on the live server and press the submit button  it seams the page just reloads

If you goto www.jobstreampro.com and click on the contact button and press the submit button  you can see what it does on the live server.

Question?  Do I need to register a route (in the Global.asax page) for the EmailController?  The only route I see if for "Home".
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38721102
If your RegisterRoutes method shows:

routes.MapRoute(
    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
);

Open in new window


...then you shouldn't. The reason you see "Home" is because it is being designated as the default controller if no controller is detected in the URL. So when people browse using just the domain (e.g. www.jobstreampro.com), no controller is detected, so Home is selected.

In your case, I assume you have the EmailController at the same level as HomeController. I gather that from what you posted above:


Because of this, the routing of MVC detects "Email" as the controller, and "Confirmation" as the action. This is what the placeholders "{controller}" and "{action}" represent in the above snippet.

Let me ask you this:  Why post back to the same page? Why not have the action of your form pointed to the EmailController directly? To me, it would seem that you would want email-related activities within the EmailController.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38721125
Can you post a screenshot of your view hierarchy? That is, can display the relationship within Solution Explorer of Home and Email? I tried to hit your Email controller directly (e.g. http://www.jobstreampro.com/Email/Confirmation) and it's coming back as a non-existent page.
0
 

Author Comment

by:mmsi
ID: 38721155
I won't be able to post a view hierarchy of the project I have on my local host until later tonight.  However, the following is the screen shots from the live server (godaddy).

Controllers Screenshot
Views Screenshot
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38721232
Is "Confirmation" both the name of the .cshtml file and the name of the action (i.e. method) within the Email controller?
0
 

Author Comment

by:mmsi
ID: 38722376
Yes, both the file and the name of the action have the same name.

public ActionResult Confirmation()
        {  
            return View();
        }


"Let me ask you this:  Why post back to the same page? Why not have the action of your form pointed to the EmailController directly? To me, it would seem that you would want email-related activities within the EmailController."

How could I post back to the EmailController from the contact view?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38722456
How could I post back to the EmailController from the contact view?
Specify that info in the BeginForm method:

@using (Html.BeginForm("Confirmation", "Email"))

Open in new window


You would want, I imagine, to move the emailing code to that page, though. This is all dependent on your architecture and how you would like to organize things.

It seems as though you have been working at this since my previous test. Now it appears you have errors in your view. I can hit the http://www.jobstreampro.com/Email/Confirmation page, but it's displaying the internal error (be sure to turn this functionality off when you go live). You have the Confirmation view pointed to the Global.asax for a code-behind. That is not correct.
0
 

Accepted Solution

by:
mmsi earned 0 total points
ID: 38723152
I'm not sure if I could reward points for the answer to this question.  However, I want to thank you for taking the time to help me, and I appreciate the advice.

I removed all files from the live server and then uploaded new files.  When I press the submit button it is now displaying the confirmation page.
0
 

Author Closing Comment

by:mmsi
ID: 38734196
The problem appears not to be code related, and no expert actually gave me the answer I needed to solve this problem.  I simply deleted my files off the live server and re-uploaded the files.  This fixed my problem and this is the reason why I'm accepting my own solution.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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