tags:

views:

74

answers:

3

Hi,

I want to create a view that contains two forms with their submit buttons.

on submitting form ajax update should happen.

So how Html herlper class will help me?

A: 

Can you please be more specific? ;)

thanx

Marko
A: 

If you are referring to the Html.BeginForm(), it has overloads where you can specify both action and controller.

Thomas Eyde
A: 

With .post with jQuery:

<script type="text/javascript">
    $(document).ready(function() {
        $("#OneForm").submit(function() {
            var f = $("#OneForm");
            var action = f.attr("action");
            var serializedForm = f.serialize();
            $.post(action, serializedForm, function(data) {
            });
            return false;
        });

        $("#TwoForm").submit(function() {
            var f = $("#TwoForm");
            var action = f.attr("action");
            var serializedForm = f.serialize();
            $.post(action, serializedForm, function(data) {
            });
            return false;
        });

    });
</script>


<% 
    using (Html.BeginForm<OneController>
    (p => p.ActionOne(), FormMethod.Post, 
    new { id = "OneForm", name = "OneForm" }))
    { 
%>
<!-- yout first form here with its submit button -->
<%=Html.AntiForgeryToken() %>
<%
    }
%>

<% 
    using (Html.BeginForm<TwoController>
    (p => p.ActionTwo(), FormMethod.Post, 
    new { id = "TwoForm", name = "TwoForm" }))
    { 
%>
<!-- yout second form here with its own submit button -->
<%=Html.AntiForgeryToken() %>
<%
    }
%>
Johannes Setiabudi
Excellent!I was using another way to define form attribute.<% using(Html.BeginForm("Create", "Home", FormMethod.Post, new {id = "frmCreate" })){%>
Vikas