【问题标题】:Unable to access ViewBag in JQuery Dialog in MVC无法在 MVC 中的 JQuery 对话框中访问 ViewBag
【发布时间】:2014-03-13 20:15:55
【问题描述】:

无法访问对话框窗口内的 viewBag 数据。 Dialog 外部显示用户 ID,但 Dialog 内部不显示用户 ID 脚本

<script>
    $(function () {
        $("#dialog").dialog({
            autoOpen: false,
            modal: true,
            width: 339,
            overlay: {
                backgroundColor: 'red',
                opacity: 0.5
            },
            show: {
                effect: "blind",
                duration: 500
            },
            hide: {
                effect: "explode",
                duration: 700
            }
        });
    });

    function OpenDialog()
    {
        $('#dialog').dialog("open");
    }
</script>

<div id="open" onclick="OpenDialog();">Click To Open</div>  

  @ViewBag.UserID
    <div id="dialog">   
            <table>
                <tr>
                    <td>User ID</td>
                    <td>@ViewBag.UserID</td>
                </tr>
                <tr>
                    <td>Comments</td>
                    <td>@Html.TextArea("CommentsTextBox")</td>
                </tr>
            </table>
            <div class="alignCenter"> 
                 <input type="submit" value="Add" /> 
                 <input type="button" value="Cancel" /> 
            </div>
    </div>

【问题讨论】:

    标签: jquery asp.net-mvc jquery-ui-dialog


    【解决方案1】:

    正如它所列出的,我看不出你的 cshtml 有什么问题。

    http://dotnetfiddle.net/clz3Md

    【讨论】:

    • 我已经更新了我的问题,你现在可以检查一下吗? ViewBag 未在 JQuery 对话框中显示值
    • 你还应该在你的脚本声明中添加一个类型属性dotnetfiddle.net/6yWqQo
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多