Why is my form triggering the wrong controller action?

Posted by COCoach on Stack Overflow See other posts from Stack Overflow or by COCoach
Published on 2010-12-23T05:49:03Z Indexed on 2010/12/23 5:54 UTC
Read the original article Hit count: 219

This form has multiple submit buttons, when clicked, it calls a simple JavaScript function to change the value of a hidden input (function is called "setHidden". This worked before, after some other not relevant code, it has ceased working. Essentially, the action it is supposed to call is never called, instead it seems to default back to a previous URL.

The Form:

<form action="/League/RemoveOwner" method="post">
    <input type="hidden" value="1007" name="lid"/>
    <input type="hidden" value="0" id="index" name="index"/>
    <input type="image" src="../../Resources/Images/Delete.png"
           height="12" alt="Remove Owner" title="Remove Owner"
           onclick="setHidden('index', '1031')"/></a> coach<br />
</form>

The Controller:

[HttpPost]
public ActionResult RemoveOwner(int id, string index)
{
    //yada
    return PartialView();
}

When clicking the image, it should call the remove owner controller, instead it calls the "View" controller:

public ActionResult View(int id)  {  
//yada
return View();
}

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about form