-1

I have a ASP.NET mvc application with the view like:

@using (Html.BeginForm("FormSubmit", "HomeController", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal" }))
    {    
            <fieldset>

                <!-- Form Name -->
                <legend>Survey Form</legend>

                <br>
                <br>

                 <centre> <p> This is a survey for User X. <p>
                 </centre>

                    <!-- Multiple Radios -->
                    <div class="form-group">
                        <label class="col-md-4 control-label" for="q1">Any Plans to attend college?</label>
                        <div class="col-md-4">
                            <div class="radio">
                                <label for="q1-0">
                                    <input type="radio" name="Q1" id="q1-0" value="1">
                                    Yes
                                </label>
                            </div>
                            <div class="radio">
                                <label for="q1-1">
                                    <input type="radio" name="Q1" id="q1-1" value="2">
                                    No
                                </label>
                            </div>
                        </div>
                    </div>

      <input type="submit" name="SaveButton" value="Save" align="center">  

       </fieldset>

 }

I created the controller in HomeController:

   [HttpPost]
   public ActionResult FormSubmit(int Q1)
    {
        return Content(Request.Form["SaveButton"]);
       //  return RedirectToAction("Index");
    }

Now when I try the button it gives me a:

  Server Error in '/surveyapps' Application.
  The resource cannot be found.

I did exactly as said in this post at stack-overflow: asp.net mvc form not posting parameter values

Any way the error could be resolved? I sam sure if I get the form values then I can just insert them into database.

5
  • 1
    Why are you using "SaveButton" ? (in Content(Request.Form["SaveButton"]);) - You are trying to read a value from a submit btn - makes no sense. Commented Nov 2, 2017 at 7:23
  • no, its just to see that I get some value from the form post operation... it makes no sense otherwise. Commented Nov 2, 2017 at 7:27
  • You Can try And remove this Line:new { ReturnUrl = ViewBag.ReturnUrl } Commented Nov 2, 2017 at 7:29
  • 4
    Just Change "HomeController" to "Home" in your beginform it works... Commented Nov 2, 2017 at 7:30
  • Ohh, havent seen that Commented Nov 2, 2017 at 7:33

1 Answer 1

0

In your view, change the HomeController to Home

like this:

@using (Html.BeginForm("FormSubmit", "Home", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal" }))

The framework handles this with "Controller" suffix automatically

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.