tags:

views:

105

answers:

0

So I have this ascx (partialView) control - ControlTemp

I have an ajax.BeginForm inside ControlTemp like this:

 <% using (Ajax.BeginForm("ControlTemp",  new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "divControlTemp" })) {
        ....
        <input type = "submit"  />
        <%}%>

Inside my masterpage, I am using this partialView as

  <div id = "divControlTemp">  <% Html.RenderAction("ControlTemp", "Home", null); %></div> 

Now the problem is if I have a page that is using this master page and the page does a postback to post, this function is also being fired:

[ActionName("ControlTemp"), AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ControlTemp(string URL)
        {
            ...
            return PartialView("ControlTemp");
        }

NOTE: Even if I use Html.BeginForm instead of Ajax.BeginForm, the above methods still ends up being triggered

The page that is using this masterpage:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="loginTitle" ContentPlaceHolderID="TitleContent" runat="server">
    Log On
</asp:Content>

<asp:Content ID="loginContent" ContentPlaceHolderID="MainContent" runat="server">
    <h2>Log On</h2>
    <p>
        Please enter your username and password. <%= Html.ActionLink("Register", "Register") %> if you don't have an account.
    </p>
    <%= Html.ValidationSummary("Login was unsuccessful. Please correct the errors and try again.") %>

    **<% using (Html.BeginForm("LogOn", "Account")) { %>**
        <div>
            <fieldset>
                <legend>Account Information</legend>
                <p>
                    <label for="username">Username:</label>
                    <%= Html.TextBox("username") %>
                    <%= Html.ValidationMessage("username") %>
                </p>
                <p>
                    <label for="password">Password:</label>
                    <%= Html.Password("password") %>
                    <%= Html.ValidationMessage("password") %>
                </p>
                <p>
                    <%= Html.CheckBox("rememberMe") %> <label class="inline" for="rememberMe">Remember me?</label>
                </p>
                <p>
                    <input type="submit" value="Log On" />
                </p>
            </fieldset>
        </div>
    <% } %>
</asp:Content>

See the Html.BeginForm in above code... The LogOn actionmethod is being fired, but it is firing ActionMethod of this another form as well!

Another person posted this problem, but s/he did not have a solution:

http://stackoverflow.com/questions/523695/post-method-called-on-mvc-usercontrols-as-well-as-their-parent-views