2012-05-22 37 views
0

我在ASP.NET MVC3中開發,我有下面的代碼來發送包含一些JavaScript的視圖,它將被加載到客戶端的jQuery UI對話框中,但我沒有看到Javascript代碼在客戶端的任何地方,ASP.NET Javascript沒有被髮送到jQuery UI對話框

查看:

@model APS.HelpDesk.Data.App_TaskComment 
<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> 
@using (Ajax.BeginForm("AllAddComment", new { area = "Task" }, new AjaxOptions 
{ 
    HttpMethod = "POST", 
    InsertionMode = InsertionMode.Replace, 
    LoadingElementId = "AddCommnetloadingGif", 
    UpdateTargetId = "AllCommentList" + Model.TaskId, 
    OnSuccess = " $('#AddCommentDialog').dialog('close');" 
})) 
{ 
    @Html.ValidationSummary(true) 
    @Html.HiddenFor(model => model.TaskId) 
    <input type="hidden" value="@Model.TaskId" id="TaskId" /> 
    <div class="editor-label"> 
     @Html.Label("کامنت جديد") 
    </div> 
    <div class="editor-field"> 
     <textarea id="CommentText" rows="2" name="CommentText" data-val-required="نوشتن کامنت ضروری است" 
      data-val="true" cols="20"></textarea> 
     <br /> 
     @Html.ValidationMessageFor(model => model.CommentText) 
    </div> 
    <p> 
     <input type="submit" value="ارسال" /> 
    </p> 
    <div id="AddCommnetloadingGif" style="display: none"> 
     <img src="@Url.Content("~/Content/Images/ajax-loader/1.gif")" /> 
    </div> 
} 
<script type="text/javascript"> 
    $(document).ready(function() { 
     bkLib.onDomLoaded(function() { 
      new nicEditor({ iconsPath: '@Url.Content("~/Content/WYSIWYG/nicEditorIcons.gif")' }).panelInstance('CommentText'); 
     }); 
    }); 
</script> 

Dialog的代碼fromFirebug

<div style="outline: 0px; height: auto; width: 500px; position: absolute; top: 385px; left: 379px; display: block; z-index: 1002; " class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable" tabindex="-1" role="dialog" aria-labelledby="ui-dialog-title-AddCommentDialog"><div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"><span class="ui-dialog-title" id="ui-dialog-title-AddCommentDialog">ايجاد کامنت جديد</span><a href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button"><span class="ui-icon ui-icon-closethick">close</span></a></div><div id="AddCommentDialog" style="text-align: right; width: auto; min-height: 108px; height: auto; " class="ui-dialog-content ui-widget-content"> 

<form action="/Task/Task/AllAddComment" data-ajax="true" data-ajax-loading="#AddCommnetloadingGif" data-ajax-method="POST" data-ajax-mode="replace" data-ajax-success=" $('#AddCommentDialog').dialog('close');" data-ajax-update="#AllCommentList15" id="form0" method="post"><input data-val="true" data-val-number="The field TaskId must be a number." data-val-required="The TaskId field is required." id="TaskId" name="TaskId" type="hidden" value="15"> <input type="hidden" value="15" id="TaskId"> 
    <div class="editor-label"> 
     <label for="">کامنت جديد</label> 
    </div> 
    <div class="editor-field"> 
     <textarea id="CommentText" rows="2" name="CommentText" data-val-required="نوشتن کامنت ضروری است" data-val="true" cols="20"></textarea> 
     <br> 
     <span class="field-validation-valid" data-valmsg-for="CommentText" data-valmsg-replace="true"></span> 
    </div> 
    <p> 
     <input type="submit" value="ارسال"> 
    </p> 
    <div id="AddCommnetloadingGif" style="display: none"> 
     <img src="/Content/Images/ajax-loader/1.gif"> 
    </div> 
</form> 
</div><div class="ui-resizable-handle ui-resizable-n" style=""></div><div class="ui-resizable-handle ui-resizable-e" style=""></div><div class="ui-resizable-handle ui-resizable-s" style=""></div><div class="ui-resizable-handle ui-resizable-w" style=""></div><div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se ui-icon-grip-diagonal-se" style="z-index: 1001; "></div><div class="ui-resizable-handle ui-resizable-sw" style="z-index: 1002; "></div><div class="ui-resizable-handle ui-resizable-ne" style="z-index: 1003; "></div><div class="ui-resizable-handle ui-resizable-nw" style="z-index: 1004; "></div></div> 

回答

0

奇怪,我能看到它,也腳本作品(放一個ñalert):

enter image description here

這是我的測試代碼(簡化當然,除去所有的噪音):

型號:

public class App_TaskComment 
{ 
    public int TaskId { get; set; } 
    public string CommentText { get; set; } 
} 

控制器:

public class HomeController : Controller 
{ 
    public ActionResult Index() 
    { 
     return View(); 
    } 

    public ActionResult Dialog() 
    { 
     var model = new App_TaskComment(); 
     return PartialView("_dialog", model); 
    } 
} 

主視圖(~/Views/Home/Index.cshtml):

<script type="text/javascript"> 
    $(function() { 
     var url = '@Url.Action("dialog")'; 
     $('<div id="dialog">Loading...</div>').appendTo('body').dialog({ 
      modal: true 
     }).load(url, { }); 
    }); 
</script> 

<div id="AddCommentDialog"></div> 

對話部分滿載AJAX(~/Views/Home/_Dialog.cshtml):被觸發

@model App_TaskComment 
<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> 
@using (Ajax.BeginForm("AllAddComment", new { area = "Task" }, new AjaxOptions 
{ 
    HttpMethod = "POST", 
    InsertionMode = InsertionMode.Replace, 
    LoadingElementId = "AddCommnetloadingGif", 
    UpdateTargetId = "AllCommentList" + Model.TaskId, 
    OnSuccess = "$('#AddCommentDialog').dialog('close');" 
})) 
{ 
    @Html.ValidationSummary(true) 
    @Html.HiddenFor(model => model.TaskId) 
    <input type="hidden" value="@Model.TaskId" id="TaskId" /> 
    <div class="editor-label"> 
     @Html.Label("کامنت جديد") 
    </div> 
    <div class="editor-field"> 
     <textarea id="CommentText" rows="2" name="CommentText" data-val-required="نوشتن کامنت ضروری است" 
      data-val="true" cols="20"></textarea> 
     <br /> 
     @Html.ValidationMessageFor(model => model.CommentText) 
    </div> 
    <p> 
     <input type="submit" value="ارسال" /> 
    </p> 
    <div id="AddCommnetloadingGif" style="display: none"> 
     <img src="@Url.Content("~/Content/Images/ajax-loader/1.gif")" /> 
    </div> 
} 
<script type="text/javascript"> 
    $(document).ready(function() { 
     bkLib.onDomLoaded(function() { 
      new nicEditor({ iconsPath: '@Url.Content("~/Content/WYSIWYG/nicEditorIcons.gif")' }).panelInstance('CommentText'); 
     }); 
    }); 
</script> 
+0

警報,但我不能看到螢火蟲的警報。 – ePezhman

+0

你在看FireBug?你看我的屏幕截圖中顯示的控制檯選項卡?這是你看到AJAX請求的地方。然後簡單地展開它並分析服務器返回的響應。你會看到腳本。當添加AJAX時,瀏覽器直接解釋內聯腳本。它實際上並沒有將它們添加到DOM,所以如果您使用FireBug探索您的DOM,您將不會看到它們。 –