简体   繁体   中英

form name in mvc url.action

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?

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

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"></script> 
<script type='text/javascript'>
    function validate() {
        alert('hello');
    }
    $(document).ready(function () {

        $("#PasswordForm").submit(function () {
            if (validate()) return true; 
        else return false; });
});
</script> 
</body>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM