tags:

views:

40

answers:

1

I just started building a small simple Website on ASP.NET MVC, in a page I am using a Partial view, the Partial View represents a simple Form which should be submitted on button click, and If I click the first Time it is submitted with success and does return my partial view with my validation Messages (if the content is invalid) but if I wish to try again the Action isn't called again. Any Idea?

View:

    <form action="<%= Url.Action("ChangePassword", "Account") %>" method="post" id="jform">
    <div>
        <fieldset>
            <legend>Account Information</legend>
            <p>
                <label for="currentPassword">Current password:</label>
                <%= Html.Password("currentPassword") %>
                <%= Html.ValidationMessage("currentPassword") %>
            </p>
            <p>
                <label for="newPassword">New password:</label>
                <%= Html.Password("newPassword") %>
                <%= Html.ValidationMessage("newPassword") %>
            </p>
            <p>
                <label for="confirmPassword">Confirm new password:</label>
                <%= Html.Password("confirmPassword") %>
                <%= Html.ValidationMessage("confirmPassword") %>
            </p>
            <p>
                <input type="submit" value="Change Password" />
            </p>
        </fieldset>
    </div>
</form>
<!--<% } %>-->
</div>

<script>
    $(function() {
        $('#jform').submit(function() {
            $('#jform').ajaxSubmit({ target: '#FmChangePassword' }); return false;
        });
    });

    /*$(document).ready(function() {
    $('#jform').live('submit', function() {
            $.post($(this).attr('action'), $(this).serialize(), function(data) {
                $("#jform").replaceWith($(data));
            });
            return false;
        });
    });*/

</script>

Part of the Controller:

        if (!ValidateChangePassword(currentPassword, newPassword, confirmPassword))
        {
            return PartialView(ViewData);                
        }
+1  A: 

Use FireBug to look at the returned HTML, check if everything is OK. Check in the console of FireBug to see what data (and to where) is posted the second time you click.

Gidon
Well thanks for your hint, I did it and there is the problem I just thought about. After Coming back to my partial view the Form contains in the Action attribute the name of the Action but not of the Controller.Instead of:<form id="jform" method="post" action="Account/ChangePassword">it returns<form id="jform" method="post" action="ChangePassword">A idea because the system does this? Have I to assign the Controller using jQuery may be???Thanks in advanceJohannes
john84
perhaps just return "return PartialView()", without the viewdata object in the constructor. That might be the cause.
Gidon
No I just tried it, the problem does exist even if I drop viewData from the Constructor call.
john84