I have an achor tag from which I want to postback to my controller action.
@using (Html.BeginForm("ActionName","Home",FormMethod.Post))
{
<div class="toolbar_button">
@{
var Route = Url.Action("ActionName", "Home");
var Anchor = MvcHtmlString.Create(String.Format("<a href=\"\"><img src=\"../../Content/Images/image.png\"></img>stringname</a>"));
}
@Anchor
</div>
}
I do have a controller function which defined
[HttpPost]
public ActionResult ActionName(viewModel)
{
}
Whenever I m clicking the anchor tag, it is not coming to this action.
Any ideas?
If you have only one form on the page you can add onclick handler to the A-tag: document.forms[0].submit()
Another, preferred way to achieve this would be to add an input element with type submit:
<input type="submit" value="Submit Form" />
You cannot POST with a plain link.
Here is some options: