Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC3中的确认密码问题_C#_.net_Asp.net Mvc 3 - Fatal编程技术网

C# MVC3中的确认密码问题

C# MVC3中的确认密码问题,c#,.net,asp.net-mvc-3,C#,.net,Asp.net Mvc 3,我使用以下模型来控制用户输入并注册他。 但如果我输入相同的密码并按下按钮,则会显示确认密码错误的消息。 我确信这个模型是正确的,因为它可以在其他页面上使用。 在这种情况下,RegisterModelSecond是EventFrontEndViewModel的成员 因此,当我评论[Compare(“RegisterModel.Password”,ErrorMessage=“密码和确认密码不匹配。”)]时,它可以工作,但我不需要确认 你知道怎么修吗 public class EventFrontEn

我使用以下模型来控制用户输入并注册他。 但如果我输入相同的密码并按下按钮,则会显示确认密码错误的消息。

我确信这个模型是正确的,因为它可以在其他页面上使用。 在这种情况下,RegisterModelSecondEventFrontEndViewModel的成员

因此,当我评论
[Compare(“RegisterModel.Password”,ErrorMessage=“密码和确认密码不匹配。”)]
时,它可以工作,但我不需要确认

你知道怎么修吗

public class EventFrontEndViewModel
    {
        public Page CurrentPage { set; get; }

        public List<Event> Events { set; get; }

        public List<Event> SubscribedEvents { set; get; }

        public RegisterModelSecond RegisterModel { set; get; }

        public EventFrontEndViewModel()
        {
            CurrentPage = new Page();
            Events = new List<Event>();
            RegisterModel = new RegisterModelSecond();
            SubscribedEvents = new List<Event>();
        }
    }
和HTML

<div class="editor-label">
                                        @Html.LabelFor(m => m.RegisterModel.Password)
                                    </div>
                                    <div class="editor-field">
                                        @Html.PasswordFor(m => m.RegisterModel.Password)
                                        @Html.ValidationMessageFor(m => m.RegisterModel.Password)
                                    </div>
                                    <div class="clear">
                                    </div>
                                    <div class="editor-label">
                                        @Html.LabelFor(m => m.RegisterModel.ConfirmPassword)
                                    </div>
                                    <div class="editor-field">
                                        @Html.PasswordFor(m => m.RegisterModel.ConfirmPassword)
                                        @Html.ValidationMessageFor(m => m.RegisterModel.ConfirmPassword)
                                    </div>
                                    <div class="clear">
                                    </div>

@LabelFor(m=>m.RegisterModel.Password)
@PasswordFor(m=>m.RegisterModel.Password)
@Html.ValidationMessageFor(m=>m.RegisterModel.Password)
@LabelFor(m=>m.RegisterModel.ConfirmPassword)
@PasswordFor(m=>m.RegisterModel.ConfirmPassword)
@Html.ValidationMessageFor(m=>m.RegisterModel.ConfirmPassword)

我在这里找到了正确答案

这是客户端验证脚本中的一个错误:jquery.validate.unobtrusive.js

在第284行,您会发现:

element = $(options.form).find(":input[name=" + fullOtherName + "]")[0];
将其更改为:

element = $(options.form).find(":input[name='" + fullOtherName + "']")[0];
name属性需要单引号



我想补充一点,如果你使用MIN版本,你也必须在那里更改它。

Wow。。你救了我一天。。谢谢
element = $(options.form).find(":input[name='" + fullOtherName + "']")[0];