无法在MVC中的JQuery Dialog中访问ViewBag

时间:2014-03-13 11:58:25

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

无法访问“对话框”窗口中的viewBag数据。 Dialog外部显示User ID,但Dialog内部不显示UserID 脚本

<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>

1 个答案:

答案 0 :(得分:2)

如上所列,我发现你的cshtml没有任何问题。

http://dotnetfiddle.net/clz3Md