簡體   English   中英

在模式彈出窗口中插入功能強類型的創建視圖

[英]Inserting a functional strongly-typed create view in a modal popup

我想在我的站點上有一個菜單項,無論我在站點中的什么位置,該菜單項都應打開一個創建視圖。 該視圖將基本屬性插入數據庫的表中。 這是視圖:

<!DOCTYPE html>

@model ITS.Models.Server
@using System.Web.Mvc.Ajax
<html>
<head>
    <meta name="viewport" content="width=device-width" />
</head>
<body>
    <div title="boo, this is a popup">Get that pop-up
    @using (Ajax.BeginForm("AddServer", new AjaxOptions { OnSuccess = "onSuccess" }))
    {
        @Html.AntiForgeryToken()
        <div>
            <fieldset>
                <legend>Add a new server</legend>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Server_Name)
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(model => model.Server_Name)
                </div>
                <div class="editor-label">
                    @Html.ValidationMessageFor(model => model.Server_Name)
                </div>

                <p>
                    <input type="submit" value="Submit" />
                </p>
            </fieldset>
        </div>
    }
    </div>
</body>
</html>

我的控制器非常簡單:

public ActionResult AddServer()
        {
            return View();
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult AddServer([Bind(Include = "Server_Name")] Server @server)
        {
            if (ModelState.IsValid)
            {
                db.Servers.Add(@server);
                db.SaveChanges();
            }
            return PartialView(@server);
        }

首先,有可能嗎? 我畢竟希望能夠通過模型插入值。 我至少嘗試用本文中的答案在彈出窗口中將其可視化,但沒有成功: 以彈出窗口打開視圖打開沒有內容的彈出窗口...

避免很多麻煩,並使用jQuery UI,ExtJS或Kendo之類的Javascript庫。 所有這些都有大量的文檔,使呈現對話框的Javascript和CSS部分非常輕松。 這些庫已經被大眾測試和“祝福”了,幾乎不需要編寫自己的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM