0

おそらく目の前にあるjQueryダイアログに問題がありますが、わかりません...

ダイアログは正常に機能します。フィールドを表示して情報を送信し、該当する場合は検証メッセージを返します。私の問題は、それを初期化するときに、if 内に div を非表示にするように指示すると、それが実行されることです。開いたときにdivはありませんが、情報を送信しようとすると検証メッセージが返され、divが表示されます。

ダイアログを呼び出すjsは次のとおりです。

$(function () {
$('.openDialog').click(function () {
    $.ajax({
        url: this.href,
        type: 'GET',
        cache: false,
        data: { idUsuario: $('#idUsuario').val() },
        success: function (result) {
            $('#result').html(result).dialog('open');
            $('#formButtom').hide();
        }
    });
    return false;
});

$('#result').dialog({
    autoOpen: false,
    modal: true,
    show: { effect: "drop", direction: "up" },
    dialogClass: "dialog",
    width: 400,
    resizable: false,
    position: "center",
    buttons: {
        "Confirmar": function () {
            $("form").submit();
        },
        "Cancelar":function () { $('#result').dialog('close'); }            
    }        
});    
});
 function dialogSucces(result) {
if (result.cadastro) {
    $('#result').dialog('close');        
    window.location.href = '/usuario/index';
} else {
    $('#result').html(result);
}
}

ここにhtmlがあります:

<form id="createUsuarioForm">
    Nome
        <div class="editor-field">
            @Html.EditorFor(model => model.Nome)<br />
            @Html.ValidationMessageFor(model => model.Nome, String.Empty, new { @class = "text-error"})
        </div>
    <br />
    E-mail / Login
        <div class="editor-field">
            @Html.EditorFor(model => model.Login)<br />
            @Html.ValidationMessageFor(model => model.Login, String.Empty, new { @class = "text-error"})
        </div>
    <br />
    <div id="formButtom" class="row demo-row">
        <div class="span2">
            <input type="submit" value="Confirmar" class="btn btn-primary" />
        </div>
        <div class="span2">
            @Html.ActionLink("Cancelar", "Index", "Usuario", new { @class = "btn btn-primary" })
        </div>
    </div>
</form>

この投稿を見たことがあります: jQuery Show/Hide not working after postbackで、関数内でこれを実行しようとしましたが、うまくいきませんでした:

$(function () {
$('.openDialog').click(function () {
    $.ajax({
        url: this.href,
        type: 'GET',
        cache: false,
        data: { idUsuario: $('#idUsuario').val() },
        success: function (result) {
            $('#result').html(result).dialog('open');
            $('#formButtom').hide();
        }
    });
    return false;
    if (this.isPostback) { $('#formButtom').hide(); };
});

私が間違っていることを誰かが知っていますか?

4

1 に答える 1

0

関数がどのように実行されるかは示されていませんdialogSuccessが、フォーム障害の場合にも実行されると思います。その場合は、if elseステートメントに行を追加する必要があります。このような:

function dialogSucces(result) {
  if (result.cadastro) {
    $('#result').dialog('close');        
    window.location.href = '/usuario/index';
  } else {
    $('#result').html(result);
    $('#formButtom').hide(); // once defected form rendered again,
                             // div hide directive should be launched again too
  }
}
于 2013-04-29T13:18:26.120 に答える