开发者

post to actionrequest from an anchor

开发者 https://www.devze.com 2022-12-27 03:05 出处:网络
I have the following; <% using(Html.BeginForm(\"GetRecommendedProducts\", \"Home\", FormMethod.Post)) { %>

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消