Вопрос

Я разрабатываю в 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>
.

Диалоговое окно, код отфиребуга

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

Введите описание изображения здесь

И вот мой тестовый код (упрощенный курс, чтобы удалить весь шум):

Модель:

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