0

ASP.NET MVC 3 を使用しています。View Novo をユーザーに提示するたびに、この View をダイアログとして開く必要があります。

コントローラ

 public ActionResult Index()
        {
            IndexViewModel viewModel = new IndexViewModel(); 
            viewModel.listaRedes = new SwitchBLL().GetRedes();
            return View(viewModel);
        }

        public ActionResult Novo()
        {
            return View(new Redes());
        }

        [HttpPost]
        public ActionResult Novo(Redes model)
        {
            if (ModelState.IsValid)
            {
                //Do something
                ModelState.AddModelError("", "Cadastrado com sucesso!");
            }
            else
            {
                ModelState.AddModelError("", "Não foi possível cadastrar. Por favor, tente novamente!");
            }
            return View(model);
        }

インデックス ビュー

@model CW.ViewModel.Redes.IndexViewModel
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<button class="btnNovo" onclick="openDialog('Nova rede','Redes/Novo')">Novo</button>
<table class="listas" id="rowSwitches" style="width: 100%;">
    @foreach (var rede in Model.listaRedes)
    {<tr onclick="jqGetRede(@rede.rede_id)" title="Detalhes do Servidor @rede.rede_u_name" >
        <td>
            <img width="12" src="/Content/Master/edit-icon.png" alt="Editar" />
        </td>
        <td style="text-align: left;">@rede.rede_u_name
        </td>
    </tr>}
</table>

ダイアログonclick="openDialog('Nova rede','Redes/Novo')"を開く方法は次のとおりです。ビューが初めて開いたときは正常に動作しますが、HttpPost が返されたときにページがダイアログとして開かれません。View Novo のコンテンツを div に配置し、(document).ready 関数を使用して JQuery 関数ダイアログを呼び出して、常にダイアログとして開くようにしましたが、機能しませんでした。

関数 openDialog

function openDialog(title, url) {
            $('.opened-dialogs').dialog("close");

            $('<div class="opened-dialogs">').html('loading...').dialog({
                position: ['center', 20],
                resizable: true,
                draggable: true,
                open: function () {
                    $(this).load(url);

                },
                close: function (event, ui) {
                    $(this).remove();
                },

                title: title,
                minWidth: 600
            });
            return false;
        }  

ノボ ビュー

@model CW.Models.Redes.Redes
@{
    Layout = null;
}
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true, "")
    <div id="addNew">
        <fieldset>
            <legend>Novo</legend>
            <div class="editor-label">
                @Html.LabelFor(m => m.NomeServidor)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.NomeServidor)
                @Html.ValidationMessageFor(m => m.NomeServidor)
            </div>
            <div class="editor-label">
                @Html.LabelFor(m => m.TipoServidor)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.TipoServidor)
                @Html.ValidationMessageFor(m => m.TipoServidor)
            </div>
            <div class="editor-label">
                @Html.LabelFor(m => m.Descricao)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.Descricao)
                @Html.ValidationMessageFor(m => m.Descricao)
            </div>
            <div class="editor-label">
                @Html.LabelFor(m => m.ServidorURL)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.ServidorURL)
                @Html.ValidationMessageFor(m => m.ServidorURL)
            </div>
            <p>
                <input type="submit" value="save" />
            </p>
        </fieldset>
    </div>
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript">
</script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

このビューを開くたびに、自動的にダイアログとして開く方法はありますか? 私がウェブで見つけたものは役に立ちませんでした。何か提案をお願いします。

4

0 に答える 0