views:

29

answers:

1

I have the following;

    <% using(Html.BeginForm("GetRecommendedProducts", "Home", FormMethod.Post)) { %>
        <% Html.RenderPartial("QuickQuote", Model.quickQuote); %>
        <div class="But brown" style="float:left;">
            <a href="." onclick="$.unblockUI(); return false;">Close</a>
        </div>
        <div class="But green" style="">
            <a href="." onclick="this.form.submit(); return false;">Go</a>
        </div>
    <%} %>

When I click the anchor I do not get a post to my action. I know this should be possible so what am I doing wrong?

The partial view only contains fields and not another BeginForm or anything like that.

If I use a submit button it works ok but I can't use a submit button I need to use an anchor.

+1  A: 

You need to get the id of the form element and then call submit on that:

<a href="#" onclick="document.getElementById('the_form').submit(); return false;">Go</a>

or if using jQuery:

<a href="#" onclick="$('#the_form').submit(); return false;">Go</a>

So the_form is the id of the form tag that is created from the Html.BeginForm("GetRecommendedProducts", "Home", FormMethod.Post) line.

amurra