ASP.NET MVC局部视图不叫我的行动 [英] ASP.NET MVC partial view does not call my Action

查看:133
本文介绍了ASP.NET MVC局部视图不叫我的行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始在ASP.NET MVC构建一个简单的小网站,在页面中我使用的是局部视图,局部视图重新presents一个简单的形式,它应该在点击按钮进行提交,如果我点击它第一次被成功提交,并不会返回我的部分观点与我的验证信息(如果内容是无效的),但如果我想再试一次动作不再次调用。任何想法?

查看:

 <形式的行动=<%= Url.Action(的ChangePassword,帐户)%GT;方法=邮报ID =jform>
    < D​​IV>
        <&字段集GT;
            <传奇>帐户信息与LT; /传说>
            &所述p为H.;
                <标签=currentPassword>当前密码:LT; /标签>
                &所述;%= Html.Password(currentPassword)%>
                &所述;%= Html.ValidationMessage(currentPassword)%>
            &所述; / P>
            &所述p为H.;
                <标签=新密码>新建密码:LT; /标签>
                &所述;%= Html.Password(NEWPASSWORD)%>
                &所述;%= Html.ValidationMessage(NEWPASSWORD)%>
            &所述; / P>
            &所述p为H.;
                <标签=confirmPassword>确认新密码:LT; /标签>
                &所述;%= Html.Password(confirmPassword)%>
                &所述;%= Html.ValidationMessage(confirmPassword)%>
            &所述; / P>
            &所述p为H.;
                <输入类型=提交值=更改密码/>
            &所述; / P>
        < /字段集>
    < / DIV>
< /表及GT;
&所述;! - &下;%}%GT - →;
< / DIV><脚本>
    $(函数(){
        $('#jform')。提交(函数(){
            $('#jform')ajaxSubmit会({目标:#FmChangePassword'});返回false;
        });
    });    / * $(文件)。就绪(函数(){
    $('#jform')。生活('提交',函数(){
            $。员额($(本).attr('行动'),$(本).serialize(),功能(数据){
                $(#jform)replaceWith($(数据));
            });
            返回false;
        });
    }); * /< / SCRIPT>

控制器的部分:

 如果(!ValidateChangePassword(currentPassword,NEWPASSWORD,confirmPassword))
        {
            返回PartialView(ViewData的);
        }


解决方案

使用Firebug来看看返回的HTML,检查是否一切正常。检查在Firebug的控制台,看看有什么数据(往哪里)发布你点击第二次。

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);                
        }

解决方案

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.

这篇关于ASP.NET MVC局部视图不叫我的行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆