Please go easy on me as I'm very new to MVC and web development in general.
I've inherited an ASP website which currently only has an 'OK' and 'Cancel' button. I need to break out 'OK' into two separate actions ('Add' and 'Remove'). 'Cancel' should still redirect the user back to the site homepage.
Here is the cshtml:
<script type="text/javascript">
var dict = {};
function Cancel() {
window.location = "/Home/Index/";
}
</script>
@using (Html.BeginForm("SaveServiceWindow", "Approve", FormMethod.Post, new { name = "SaveServiceWindow" }))
{
<!--
Other form controls
-->
<tr><td>Desired Action:</td></tr>
<tr>
<td align="left" width="300">
<input type="submit" value="Add Group" name="Add" id="submit" />
</td>
<td align="left" width="300">
<input type="submit" value="Remove Group" name="Remove" id="submit" />
</td>
<td align="left" width="300">
<input type="button" value="Cancel" onclick="Cancel();" />
</td>
</tr>
</table>
}
And here is how the Controller method is declared (I'm not including the method contents as it's not relevant to the question):
[HttpPost]
public ActionResult SaveServiceWindow(FormCollection collection, TemporalApprovalModel approvalInfo)
{
}
I see that a FormCollection object is being passed to this method. I found this answer which looks really promising, however, I'm a bit confused regarding how to retrofit the existing code:
- in the cshtml I have, I'm passing a method name in Html.BeginForm. Is there a permutation of BeginForm where the submit button method doesn't need to be hard-coded?
- Also, would I still be able to pass in a FormCollection object to the controller methods (as opposed to a MessageModel object as indicated in the linked answer)?