Reputation: 2451
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);
}
Upvotes: 2
Views: 1374
Reputation: 2360
You can not Javasript on Partial View. You have to define it in Parent View
Upvotes: 0
Reputation: 18491
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.
Upvotes: 1