0

I have a small problem with calling controller function. Strange is that every other submit button works fine. But this one has problem which I cannot solve for now. I will show you two forms with submit buttons becouse there is only one working fine.

Controller:

public class MyController : Controller
{
    public ActionResult MethodOne()
        {
            ...
            return RedirectToAction("index");
        }

    public ActionResult MethodTwo()
        {
            ...
            return RedirectToAction("index");
        }
}

And the view:

//This one works fine!!
@using (Html.BeginForm("MethodOne", "My", FormMethod.Post))
{
    <input id="Some-cool-id" type="submit" value="Add!" />
}

//This one doesn't work?!
@using (Html.BeginForm("MethodTwo", "My", FormMethod.Post))
{
    <input id="some-cool-id2" type="submit" value="Delete"!" />
}

Error is telling that Method2 is not in the required path.

Resource not found.

Description: HTTP 404. Searched resource (or ...) ... 

Required path URL: /My/MethodTwo

I was searching what is bad but in the end, I need a help, thanks.

4
  • I have tried delete cache and restart Visual studio. Commented Aug 30, 2013 at 12:47
  • If it can does problem, in the second form I am creating webgrid before submit button. However only showing him (don't working with data yet) Commented Aug 30, 2013 at 13:09
  • Erm... "Delete"!" -- got an extra " in there? (unless this is a copy-paste error) Commented Aug 30, 2013 at 13:27
  • That's just copy paste error. In project it is correct. Sorry for that - anyway good observation! Commented Aug 30, 2013 at 13:32

2 Answers 2

1

Add the property [HttpPost] before the method.

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

2 Comments

Didn't help, unfortunately. :(
What is the routing rule?
0

Try this,

  @using (Html.BeginForm("MethodTwo", "Test", FormMethod.Post))
    {
        <input type="submit" value="asd" />
    }


     @using (Html.BeginForm("MethodOne", "Test", FormMethod.Post))
    {
        <input type="submit" value="poll" />
    }

Controller

 public class TestController : Controller
    {

 public ActionResult MethodOne()
        {

        return RedirectToAction("CustomerInfo");
    }

    public ActionResult MethodTwo()
    {

        return RedirectToAction("CustomerInfo");
    }

 [HttpGet]
        public ActionResult CustomerInfo()
        {

        ViewBag.CustomerNameID = new SelectList(List, "CustomerId", "customerName");
        ViewBag.RegisterItems = GetAllRegisterData();
        ViewData["SampleList"] = GetAllRegisterData();
        return View();
    }
}

5 Comments

Problem was not there. Still falling.
@Ademar both the form is in same page?
Yes in the same page (View)... Really? Then I try make new controller and copy there functions.
@Ademar I just update my code. It's an example and it's perfectly working fine.
Well, I have tried create new controller and copy there all Actions. And do you know what? It started work fine. I have't got emplanation how it is possible. So thanks, found error mainly thanks you:)

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.