문제

저는 ASP.NET MVC3에서 개발하고 있으며 일부 javascript가 포함된 뷰를 보내는 코드가 있고 클라이언트 측의 jQuery UI 대화 상자에 로드되지만 클라이언트 측 어디에도 Javascript 코드가 표시되지 않습니다. ,

보다 :

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

Firebug의 대화 상자 코드

<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>
도움이 되었습니까?

해결책

이상하게도 나는 그것을 볼 수 있고 스크립트도 작동합니다 ( 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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top