I have an HTML.ActionLink that is acting perfectly except it is not hitting the POST method.
@Html.ActionLink("Join Now!", "JoinFleet", "Members", new { ID =Model.ID , fleet = 1 }, new { @class = "btn btn-primary" })
it results with the following URL as expected.
http://localhost:64096/Members/JoinFleet/2403?fleet=1
I need it to work exactly like this but, hit my POST JoinFleet
method.
I toyed with a few ways I could accomplish this task. I was also trying to pass the value of a checked radiobutton to a using as a param.
@using (Html.BeginForm("JoinFleet", "Members", new { fleet = 3 },
FormMethod.Post, new { @class = "form-group" }))
and then submit with a standard submit button I would be very happy with either making that Action hit my post method in my controller or passing the value of the radio button as the param value for fleet in my using.
When creating a link to a controller action in ASP.NET MVC, using the generic ActionLink method is preferable, because it allows for strongly typed links that are refactoring friendly.
Default: ActionLink
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
Using Button:
<input type="button" title="Delete" value="D" onclick="location.href='@Url.Action("Delete", "movies", new { id = item.ID })'" />
Using Image:
<a href="@Url.Action("Delete", "movies", new { id = item.ID })" title="Edit">
<img src="../../Content/Images/Delete.png" />
</a>