首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >局部视图在索引视图中无法正常工作。

局部视图在索引视图中无法正常工作。
EN

Stack Overflow用户
提问于 2012-09-21 13:11:21
回答 2查看 143关注 0票数 1

我正在开发MVC应用程序,并使用razor语法。

在这个应用程序中,我提供了注释工具。

我已经添加了一个局部视图,它从DB加载评论/记录。

在下图中,我们可以看到名为run-time for employee index view的注释框。

现在我们可以看到注释框,我在运行时调用,这是部分视图,但问题是我只能在第一个record...after first记录时添加注释,该按钮根本不起作用……

丢了什么东西吗?当我们调用任何局部视图运行时并对其进行操作时,是否有单独的进程?

看这张照片。

这是代码……

代码语言:javascript
复制
@model PagedList.IPagedList<CRMEntities.Customer>


  <link href="../../Content/Paging.css" rel="stylesheet" type="text/css" />
  <link href="../../Content/EventEntity.css" rel="stylesheet" type="text/css" />
  <script src="<%=Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")%>" type="text/javascript"></script>

<div id="ListBox">
    <div id="ListHeader">   
        All customers(@Model.TotalItemCount)
    </div>

    @foreach (var item in Model)
    {        

    <div id="ListContent">
          <span class="ContentTitleField">@Html.ActionLink(item.Name, "Details", new { id = item.Id }, new { @style="color:#1A6690;" })</span>
          @if (item.Owner != null)
          {               
            <span class="ContentSecondaryField">@Html.ActionLink(item.Owner.FullName, "Details", "Employee", new { id = item.OwnerId }, new { @style = "color:#1A6690;" })</span>          
          }
          <span class="ContentSecondaryField">@Html.DisplayFor(modelItem => item.Address)</span>
          <span id="flagMenus">
            @Html.Action("ShowFlag", "Flagging", new { entityId=item.Id, entityType="Customer"})
          </span>
          @if (item.Opportunities.Count > 0)
          {
                        <span class="FlagOpportunity">@Html.ActionLink("opportunities(" + item.Opportunities.Count + ")", "Index", "Opportunity", new { custid = item.Id }, new { @style = "color:#fff;" })</span>
          }

           <div style="float:right;">
             @Html.Action("SetRate", "Rating", new { entityId = item.Id, rating = item.Rating, entityname = "Customer" })

           </div>
           <div id="subscribeStatus" style="float:right;">
                @Html.Action("ShowSubscribedStatus", "Subscribing", new { entityId = item.Id, entityType = "Customer" })
            </div>
          <div class="ListLinks">          
          <span class="ListEditLinks">
            <span style="float:left;">@Html.ActionLink("edit", "Edit", new { id = item.Id })</span>
            <span class="LinkSeparator"></span>            
           </span>
           <span class="ListAddLinks">
            <span style="float:left;">@Html.ActionLink("+opportunity", "Create", "Opportunity", new { custid = item.Id }, null)</span>
            <span class="LinkSeparator"></span>
            <span>@Ajax.ActionLink("+Comment", null, null, null, new { id = item.Id, @class = "addremark" })</span>                                  
          </span>

        <div class="RemarkBox"></div>

          </div>    

             <span class="CommentAdd">

             </span>

          <div class="CommentBlock">


        </div>

         <span>@Ajax.ActionLink("Add Comment", null, null, null, new { id = item.Id, @class = "addremark" })</span>                                  



    </div>    
    } 

    <div class="PagingBox">
        @Html.Action("CreateLinks", "Pager", new { hasPreviousPage = Model.HasPreviousPage, hasNextPage = Model.HasNextPage, pageNumber = Model.PageNumber, pageCount = Model.PageCount })
    </div>

</div>

<script type="text/javascript">

    $(document).ready(function () {

        $('.RemarkBox').hide();

        $('a.addremark').click(function () {


            var url="@Html.Raw(Url.Action("ShowCommentBox", "Comment", new { Id = "idValue", EntityType = "Customer" }))";

            url=url.replace("idValue",event.target.id);
            $('.RemarkBox').load(url);

            $(this).closest('div').find('div.RemarkBox').slideToggle(300);
            return false;
        });


         $("a.pagenumber").click(function () {             
            var page = 0;
            page = parseInt($(this).attr("id"));

            $.ajax({
                url: '@Url.Action("GetPagedCustomers")',
                data: { "page": page },
                success: function (data) { $("#customerlist").html(data); }
            });
            return false;
        });

    });

</script>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-21 13:34:24

在success function中,你需要调用javascript,或者让按钮工作的jquery代码。是一个花了我很多时间的错误。任何由ajax或任何renderpartiAl上传的东西都需要调用javascript。

代码语言:javascript
复制
$('.RemarkBox').load(url, function() {
  //RECALL JAVASCRIPT

});
票数 0
EN

Stack Overflow用户

发布于 2012-10-04 22:01:13

为了扩展Alberto León所说的内容,部分页面加载不会导致文档就绪事件触发,因此在添加第一个注释之后,重新呈现的元素将不会注册javascript事件处理程序。

要解决此问题,可以将事件注册代码放入一个函数中,并从文档就绪事件和AJAX调用的成功处理程序中调用此函数。如下所示:

代码语言:javascript
复制
function AssignEventHandlers() {

    $('a.addremark').click(function () {
        ....
    });

    $("a.pagenumber").click(function () {
        var page = 0;
        page = parseInt($(this).attr("id"));

        $.ajax({
            url: '@Url.Action("GetPagedCustomers")',
            data: { "page": page },
            success: function (data) { 
                $("#customerlist").html(data);
                AssignEventHandlers();
            }
        });
        return false;
    });
}

$(document).ready(function () {

    $('.RemarkBox').hide();

    AssignEventHandlers();
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12524595

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档