Question

Je développe en ASP.NET MVC3, j'ai le code ci-dessous pour envoyer la vue qui contient du javascript, et il sera chargé dans une boîte de dialogue jQuery UI côté client, mais je ne vois le code Javascript nulle part côté client ,

Voir :

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

Code de la boîte de dialogue de 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>
Était-ce utile?

La solution

Bizarre, je le vois et aussi le script fonctionne (mettez un alert):

enter image description here

Et voici mon code de test (simplifié bien sûr pour supprimer tout le bruit) :

Modèle:

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

Manette:

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

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

Vue principale (~/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>

Boîte de dialogue partielle chargée avec 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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top