1

ここのこのページからチュートリアルをやっていて、ほとんどコピーしていました

http://ricardocovo.com/2011/04/03/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms/

そして、それは機能していません。その理由はわかりません。まったく反応がありません。

これが私の編集方法です

public ActionResult Edit(int id)
{
   ViewBag.Categories = CategoriesSelectList();

   return PartialView(proxy.GetProduct(id));
}

これが私の編集ビュー (部分ビュー) です。しかし、通常のビューとの違いはわかりません。

@model Shop.Data.ProductType

<h2>Edit</h2>
@using (Ajax.BeginForm("Edit", "Shop", null,
        new AjaxOptions
        {
            UpdateTargetId = "update-message",
            InsertionMode = InsertionMode.Replace,
            HttpMethod = "POST",
            OnSuccess = "updateSuccess"
        }, new { id = "updateShopForm" }))

       {  
   @Html.ValidationSummary(true) 

    <div id="update-message" class="error invisible"></div>

    <fieldset>
        <legend>Products</legend>


    @Html.HiddenFor(model => model.CategoryID)


    @Html.Label("Nazwa")
    <div class="editor-label">
    @Html.EditorFor(model => model.Name)
    @Html.ValidationMessageFor(model => model.Name)
    </div>
    <br />                               
     <br />
    @Html.Label("Kategoria")
     <div class="editor-label">
    @Html.DropDownList("CategoryID", new SelectList(ViewBag.Categories, "value", "text"))
    @Html.ValidationMessageFor(model => model.CategoryID) 


    </div>
        </fieldset>
}

そして、ここにチュートリアルからのこの長いJavaがあります

<div id="updateDialog" title="Update Product">

</div>

<script type="text/javascript">
    var linkObj;
    $(function () {
        $(".edit-link").button();
        $('#updateDialog').dialog({
            autoOpen: false,
            width: 400,
            resizable: false,
            modal: true,
            buttons: {
                "Update": function () {
                    $("#update-message").html(''); //make sure there is nothing on the message before we continue                         
                    $("#updateShopForm").submit();
                },
                "Cancel": function () {
                    $(this).dialog("close");
                }
            }
        });

        $(".edit-link").click(function () {
            //change the title of the dialgo
            linkObj = $(this);
            var dialogDiv = $('#updateDialog');
            var viewUrl = linkObj.attr('href');
            $.get(viewUrl, function (data) {
                dialogDiv.html(data);
                //validation
                var $form = $("#updateShopForm");
                // Unbind existing validation
                $form.unbind();
                $form.data("validator", null);
                // Check document for changes
                $.validator.unobtrusive.parse(document);
                // Re add validation with changes
                $form.validate($form.data("unobtrusiveValidation").options);
                //open dialog
                dialogDiv.dialog('open');
            });
            return false;
        });

    });


    function updateSuccess() {
        if ($("#update-message").html() == "True") {
            //we update the table's info
            var parent = linkObj.closest("tr");
            parent.find(".carName").html($("#Name").val());
            parent.find(".carDescription").html($("#Description").val());
            //now we can close the dialog
            $('#updateDialog').dialog('close');
            //twitter type notification
            $('#commonMessage').html("Update Complete");
            $('#commonMessage').delay(400).slideDown(400).delay(3000).slideUp(400);
        }
        else {
            $("#update-message").show();
        }
    }

</script>

そして、ここに私の編集リンクがあります

@Html.ActionLink("Edytuj", "Edit", new { id = m.ID }, new { @class = "edit-link" })

違いが見つかりません。

4

0 に答える 0