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?
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?
If you are referring to the Html.BeginForm(), it has overloads where you can specify both action and controller.
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() %>
<%
}
%>