0

这是发送到服务器的内容:

http://localhost:3182/Admin/UserAdmin/Save?Count=0&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D

我正在使用不显眼的 jquery.unobtrusive-ajax,它在我项目的其他页面上运行良好。我没有对 BeginForm 助手做任何花哨的事情。实际上这很简单。如果有帮助,我可以发布它,但没有太多。

我认为另一个库可能会干扰我的代码,所以我删除了其他脚本,它仍然做同样的事情。这很奇怪。有没有人见过这个并且知道如何解决它?

这是整个视图:

@using YogaDiVita.Ui.Helpers
@model YogaDiVita.Domain.YogaDiVitaContext.Model.User
@{
    ViewBag.Title = "Profile";
    Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
    var isInstructor = (bool)ViewBag.IsInstructor;

}

<link href="@Url.ContentArea("~/Scripts/plugins/fineUploader/fineuploader.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Scripts/plugins/jCrop/css/jquery.Jcrop.min.css")" rel="stylesheet"
    type="text/css" />
<div class="row-fluid">
    <div class="span12">
        <h3 class="heading">User Profile</h3>
        <div class="row-fluid">
            <div class="span8">
                @using (Ajax.BeginForm("Save",new RouteValueDictionary(), new AjaxOptions
               {
                   HttpMethod = "POST",                       
                   OnSuccess = "OnSuccess",
                   OnFailure = "OnFailure"
               }, new { @class = "form-horizontal well" }))
                {
                    @Html.HiddenFor(u => u.Id)
                    @Html.HiddenFor(u => u.CreatedById)
                    @Html.HiddenFor(u => u.ModifiedById)
                    @Html.HiddenFor(u => u.Username)
                    @Html.Hidden("isInstructor", isInstructor)
                    <fieldset>
                        <div class="control-group formSep">
                            <label class="control-label">
                                Username</label>
                            <div class="controls text_line">
                                <strong>@Model.Username</strong> <a href="/Admin/UserAdmin/ResetPassword/@Model.Id" class="btn resetPasswordWindow">Reset Password</a>
                            </div>
                        </div>
                        <div class="control-group formSep">
                            <label for="fileinput" class="control-label">
                                User avatar</label>
                            <div class="controls">
                                <div data-fileupload="image" class="fileupload fileupload-new">
                                    <div style="width: 80px; height: 80px;" class="fileupload-new thumbnail">
                                        <img src="http://www.placehold.it/108x108/EFEFEF/AAAAAA " alt="" id="userAvatar">
                                    </div>
                                    <a href="/Admin/UserAdmin/ImageUpload/@Model.Id" class="btn avatarUpload">Upload New
                                        Image</a>
                                </div>
                            </div>
                        </div>
                        <div class="control-group formSep">
                            <label for="FirstName" class="control-label">
                                First Name</label>
                            <div class="controls">
                                @Html.TextBoxFor(u => u.FirstName, new { @class = "input-xlarge" })
                            </div>
                        </div>
                        <div class="control-group formSep">
                            <label for="FirstName" class="control-label">
                                Last Name</label>
                            <div class="controls">
                                @Html.TextBoxFor(u => u.LastName, new { @class = "input-xlarge" })
                            </div>
                        </div>
                        <div class="control-group formSep">
                            <label for="u_email" class="control-label">
                                Email Address</label>
                            <div class="controls">
                                @Html.TextBoxFor(u => u.EmailAddress, new { @class = "input-xlarge" })
                            </div>
                        </div>
                        <div class="control-group formSep">
                            <label for="u_email" class="control-label">
                                Telephone Number</label>
                            <div class="controls">
                                @Html.TextBoxFor(u => u.TelephoneNumber, new { @class = "input-xlarge" })
                            </div>
                        </div>
                        <div class="control-group formSep">
                            <label for="u_email" class="control-label">
                                Mobile Number</label>
                            <div class="controls">
                                @Html.TextBoxFor(u => u.MobileTelephoneNumber, new { @class = "input-xlarge" })
                            </div>
                        </div>
                        <div class="control-group formSep">
                            <label for="u_email" class="control-label">
                                Mobile Number</label>
                            <div class="controls">
                                @Html.TextBoxFor(u => u.MobileTelephoneNumber, new { @class = "input-xlarge" })
                            </div>
                        </div>
                        <div class="control-group formSep">
                            <label for="u_email" class="control-label">
                                Is Instructor</label>
                            <div class="controls">
                                @Html.CheckBox("cbIsInstructor", isInstructor)
                            </div>
                        </div>
                        <div class="control-group">
                            <div class="controls">
                                <button class="btn btn-gebo" type="submit">
                                    Save changes</button>

                            </div>
                        </div>
                    </fieldset>

                }
            </div>
        </div>
    </div>
</div>

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"
    type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/plugins/jcrop/jquery.Jcrop.min.js")" type="text/javascript"></script>
<script src="@Url.ContentArea("~/Scripts/plugins/fineUploader/util.js")"></script>
<script src="@Url.ContentArea("~/Scripts/plugins/fineUploader/button.js")"></script>
<script src="@Url.ContentArea("~/Scripts/plugins/fineUploader/handler.base.js")"></script>
<script src="@Url.ContentArea("~/Scripts/plugins/fineUploader/handler.form.js")"></script>
<script src="@Url.ContentArea("~/Scripts/plugins/fineUploader/handler.xhr.js")"></script>
<script src="@Url.ContentArea("~/Scripts/plugins/fineUploader/uploader.basic.js")"></script>
<script src="@Url.ContentArea("~/Scripts/plugins/fineUploader/dnd.js")"></script>
<script src="@Url.ContentArea("~/Scripts/plugins/fineUploader/uploader.js")"></script>
<script src="@Url.ContentArea("~/Scripts/plugins/fineUploader/jquery-plugin.js")"></script>



<script>
    $(function () {

        loadUserAvatar();
        $('.avatarUpload').colorbox({
            initialHeight: '520',
            initialWidth: '650',
            iframe: false,
            opacity: 0.45,
            onClosed: function () {
                loadUserAvatar();
            }
        });


        $('.resetPasswordWindow').colorbox({
            initialHeight: '0',
            initialWidth: '0',
            iframe: false,
            opacity: 0.45,
            onClosed: function () {

            },
            onComplete: function () {

                $.validator.addMethod("passwordsMustMatch", function (value, element) {
                    return $('#validatePassword').val() == $('#password').val();
                }, "The passwords do not match");

                $('.resetPasswordForm').validate({
                    onkeyup: false,
                    errorClass: 'error',
                    validClass: 'valid',
                    errorPlacement: function (error, element) {
                        error.appendTo(element.closest("div.controls"));
                    },
                    highlight: function (element) {
                        $(element).closest("div.control-group").addClass("error f_error");
                        var thisStep = $(element).closest('form').prev('ul').find('.current-step');
                        thisStep.addClass('error-image');
                    },
                    unhighlight: function (element) {
                        $(element).closest("div.control-group").removeClass("error f_error");
                        if (!$(element).closest('form').find('div.error').length) {
                            var thisStep = $(element).closest('form').prev('ul').find('.current-step');
                            thisStep.removeClass('error-image');
                        };
                    },
                    rules: {
                        password: { required: true, minlength: 6, passwordsMustMatch: true },
                        validatePassword: { required: true, minlength: 6, passwordsMustMatch: true }
                    },
                    invalidHandler: function (form, validator) {
                        $.sticky("There are some errors. Please corect them and submit again.", { autoclose: 5000, position: "top-right", type: "st-error" });
                    }
                });
            }
        });

    });


    function loadUserAvatar(parameters) {
        $.ajax({
            url: '/Admin/Avatar/AvatarLoad/@Model.Id',
            type: 'POST',
            cache: false,
            timeout: 100000,
            error: function (xhr, status, error) {
                alert(error + " " + status);
            },
            success: function (data) {
                $("#userAvatar").attr("src", data.Image.ThumbNailRelativePath);
            }

        });
    }

    function OnSuccess(parameters) {
        $.sticky("The user profile has been updated successfully.", { autoclose: 5000, position: "top-right", type: "st-error" });
    }
    function OnFailure(parameters) {
        $.sticky("There was an error saving the profile. </br>" + parameters.message, { autoclose: 5000, position: "top-right", type: "st-error" });
    }
</script>

更新:

在对发生的事情进行了一些研究之后,我在发布后收到了这个错误:An item with the same key has already been added

4

2 回答 2

0

您不能直接绑定到集合 - 请参阅ASP.NET Wire Format for Model Binding to Arrays, Lists, Collections, Dictionaries,了解如何完成您正在尝试做的事情的示例。

于 2013-01-01T23:15:17.357 回答
0

嗯,我发现了这个问题。真的有点傻。问题是我的模型上有一个界面。属性用户名有 2 个版本。一个命名为 UserName(大写 N),另一个命名为 Username(小写 n)。这篇博文有帮助

于 2013-01-02T14:15:17.047 回答