0

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?

alice7
  • 3,834
  • 14
  • 64
  • 93

2 Answers2

1

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" />
MK_Dev
  • 3,291
  • 5
  • 27
  • 45
0

You cannot POST with a plain link.

Here is some options:

W3Max
  • 3,328
  • 5
  • 35
  • 61