How to postback from an anchor tag

Go To StackoverFlow.com

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?

2012-04-03 22:54
by alice7
Duplicate of http://stackoverflow.com/q/6180256/360053 - Tuan 2012-04-03 22:58
Don't use the word postback. Postback is form WebForm and it is not the same thing as a HTTP POST - W3Max 2012-04-03 23:06


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" />
2012-04-03 22:58
by MK_Dev
Actually the view consists of multiple partial views - alice7 2012-04-03 22:58
Views are not the same as forms. As long as there's only one
element on the page, it should work. If there are multiple forms on the page, I'd suggest adding a to each one - MK_Dev 2012-04-03 23:01
Is there anyway to include the image with the input type - alice7 2012-04-04 02:36
Yes, you can use


0

You cannot POST with a plain link.

Here is some options:

2012-04-03 23:02
by W3Max
Ads