2014-03-13 78 views
0

無法訪問對話框窗口中的viewBag數據。在對話外顯示用戶ID,但對話框裏面不顯示用戶名 腳本無法訪問MVC中的JQuery對話框中的ViewBag

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

回答

2

,因爲它是上市我看不出什麼毛病你CSHTML。

http://dotnetfiddle.net/clz3Md

+0

我已經更新了我的問題你現在可以檢查嗎? ViewBag在JQuery Dialog – Golda

+1

中不顯示值,你還應該爲你的腳本添加一個類型屬性decleration http://dotnetfiddle.net/6yWqQo – George