局部视图不会在索引视图propely工作。 [英] Partial View not working propely in index view.

查看:120
本文介绍了局部视图不会在索引视图propely工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发MVC应用程序,并使用剃刀语法。

在这个应用程序,我给注释设施。

我添加了一个局部视图,它加载评论/从数据库记录。

在下面的图片,我们可以看到这就是所谓的运行时间为员工索引视图的评论框。

现在我们可以看到评论框,我打电话给在运行时,这是局部的观点,但问题是,我可以只在第一个记录该按钮不会在所有的工作第一个记录后添加评论......

东西不见了?
是否有独立的过程,当我们调用任何局部视图运行时间,并在行动上呢?

查看图片...

下面是code ....

  @model PagedList.IPagedList< CRMEntities.Customer>
  <链接HREF =../../内容/ Paging.css的rel =stylesheet属性类型=文/ CSS/>
  <链接HREF =../../内容/ EventEntity.css的rel =stylesheet属性类型=文/ CSS/>
  &所述; SCRIPT SRC =&下;%= Url.Content(〜/脚本/ jquery.unobtrusive-ajax.min.js)%>中类型=文/ JavaScript的>< / SCRIPT>< D​​IV ID =列表框>
    < D​​IV ID =ListHeader>
        所有客户(@ Model.TotalItemCount)
    < / DIV>    @foreach(以型号VAR项)
    {    < D​​IV ID =的listContent>
          <跨度类=ContentTitleField> @ Html.ActionLink(item.Name,详细信息,新{ID = item.Id},{新款式@ =COLOR:#1A6690;})LT; / SPAN&GT ;
          @if(item.Owner!= NULL)
          {
            <跨度类=ContentSecondaryField> @ Html.ActionLink(item.Owner.FullName,详细信息,雇员,新{ID = item.OwnerId},{新= @style颜色:#1A6690; })LT; / SPAN>
          }
          <跨度类=ContentSecondaryField> @ Html.DisplayFor(modelItem => item.Address)LT; / SPAN>
          &所述;跨度的id =flagMenus>
            @ Html.Action(ShowFlag,检举,新的{ENTITYID = item.Id,的EntityType =客户})
          < / SPAN>
          @if(item.Opportunities.Count大于0)
          {
                        <跨度类=FlagOpportunity> @ Html.ActionLink(机会(+ item.Opportunities.Count +),索引,机遇号,新{客户ID = item.Id},{新@风格=COLOR:#FFF;})LT; / SPAN>
          }           < D​​IV的风格=浮动:权利;>
             @ Html.Action(SetRate,等级,新的{ENTITYID = item.Id,等级= item.Rating,实体名称=客户})           < / DIV>
           < D​​IV ID =subscribeStatus的风格=浮动:权利;>
                @ Html.Action(ShowSubscribedStatus,订阅,新的{ENTITYID = item.Id,的EntityType =客户})
            < / DIV>
          < D​​IV CLASS =ListLinks>
          <跨度类=ListEditLinks>
            <跨度风格=浮动:左;> @ Html.ActionLink(编辑,编辑,新{ID = item.Id})LT; / SPAN>
            <跨度类=LinkSeparator>< / SPAN>
           < / SPAN>
           <跨度类=ListAddLinks>
            <跨度风格=浮动:左;> @ Html.ActionLink(+机遇,创建,机遇号,新{客户ID = item.Id},NULL)LT; / SPAN>
            <跨度类=LinkSeparator>< / SPAN>
            <跨度> @ Ajax.ActionLink(+评论,NULL,NULL,NULL,新{ID = item.Id,@class =addremark})LT; / SPAN>
          < / SPAN>        < D​​IV CLASS =RemarkBox>< / DIV>          < / DIV>             <跨度类=CommentAdd>             < / SPAN>          < D​​IV CLASS =CommentBlock>
        < / DIV>         <跨度> @ Ajax.ActionLink(添加评论{ID = item.Id,@class =addremark},NULL,NULL,NULL,新)LT; / SPAN>    < / DIV>
    }    < D​​IV CLASS =PagingBox>
        @ Html.Action(CreateLinks,寻呼机,新的{有previousPage = Model.Has previousPage,hasNextPage = Model.HasNextPage,PAGENUMBER = Model.PageNumber,页页次= Model.PageCount})
    < / DIV>< / DIV><脚本类型=文/ JavaScript的>    $(文件)。就绪(函数(){        $('RemarkBox。')隐藏()。        $('a.addremark')。点击(函数(){
            VAR URL =@ Html.Raw(Url.Action(ShowCommentBox,注释,新{ID =idValue的EntityType =客户}));            URL = url.replace(idValue,event.target.id);
            $('。RemarkBox')负载(URL)。            $(本).closest('格')找到('div.RemarkBox')的slideToggle(300)。
            返回false;
        });
         $(a.pagenumber)。点击(函数(){
            VAR页= 0;
            页= parseInt函数($(本).attr(ID));            $阿贾克斯({
                网址:'@ Url.Action(GetPagedCustomers)',
                数据:{页:页},
                成功:功能(数据){$(#customerlist)HTML(数据); }
            });
            返回false;
        });    });< / SCRIPT>


解决方案

在成功的功能,你需要召回JavaScript或jQuery的code,使按钮的工作。那是我抽放大量的时间一个错误。凡是通过AJAX上传或任何的RenderPartial需要召回的JavaScript。

  $('。RemarkBox')。负载(URL,函数(){
  // RECALL JAVASCRIPT});

I am developing MVC application and using razor syntax.

In this application I am giving comment facility.

I have added a partial view, which loads the comment/Records from DB.

In below image, we can see the comment box which is called run-time for employee index view.

Now as we can see comment box, I called at run-time, which is partial view, but problem is I can add comment for only on first record...after first record that button wont work at all...

anything is missing ? Is there separate process when we call any partial view run-time and make in action on it ?

See the pic...

Here is the code....

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

解决方案

In success function you need to recall the javascript, or the jquery code that makes the button work. Is an error that taked me a lot of time. Anything uploaded by ajax or any renderpartiAl needs to recall javascript.

$('.RemarkBox').load(url, function() {
  //RECALL JAVASCRIPT

});

这篇关于局部视图不会在索引视图propely工作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆