tags:

views:

72

answers:

2

I am having the following <form action="<%=Url.Action("PasswordDetails",new{Controller = "User"}) %>" method="post" name="PasswordForm" id="PasswordForm" enctype="multipart/form-data">

However, the $("#PasswordForm").submit(function() { if (validate()) return true; else return false; }); isn`t being passed through.

What is wrong?

A: 

Your view page should look like this:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% using (Html.BeginForm("PasswordDetails", "User", 
                     FormMethod.Post, new { id = "PasswordForm" }))
   { %>
   <input type="password" id="sitepassword" />
   <input type="submit" value="Submit" />
<% } %>
</asp:Content>

and your site master like this:

<body>
<div class="page">
    <div id="main">
        <asp:ContentPlaceHolder ID="MainContent" runat="server" />

        <div id="footer">
        </div>
    </div>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt; 
<script type='text/javascript'>
    function validate() {
        alert('hello');
    }
    $(document).ready(function () {

        $("#PasswordForm").submit(function () {
            if (validate()) return true; 
        else return false; });
});
</script> 
</body>
Nicholas Murray
I have tried the above and it`s not working as well. I have decided to make use of <% using (Html.BeginForm("PasswordDetails", "User")) { %>... How can I add the form name to that?
I've updated my answer. You should get the hello alert now.
Nicholas Murray
+1  A: 

<% using (Html.BeginForm("PasswordDetails", "User", FormMethod.Post, new { id = "PasswordForm" })) { %>