1

私はMVC3アプリケーションを開発しており、かみそりの構文を使用しています。

このアプリケーションでは、コメント機能を提供しています。

DBからコメント/レコードをロードする部分ビューを追加しました。

これで、グリッド/テーブルのすべての行にコメントリンクを追加しました。ユーザーがそのコメントリンクをクリックすると、コメントを追加するためのコントロールのグループを含む部分ビューが読み込まれます。

以下の画面を確認してください。

ここに画像の説明を入力してください

問題は、ユーザーがコメントリンクをクリックすると、すべての行のコメントの部分ビューが開くことです...

下の画面を確認してください。

ここに画像の説明を入力してください

ユーザーがクリックした行の部分ビューを1つだけ開きたい...

私はどのように行いますか ?

以下のコードがあります。

 @model PagedList.IPagedList <CRMEntities.Location>


@{
    ViewBag.Title = "Index";
}

<div id="LocationListPageWise">
<table>
    <tr>
        <th>
            Name
        </th>
        <th>
            Remark
        </th>
        <th>
            State
        </th>
        <th>
            Region
        </th>
        <th>
            PinCode
        </th>
        <th>
            Country
        </th>
        <th>
            City
        </th>
        <th>
            Owner
        </th>
        <th>


        </th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Remark)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.State)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Region)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PinCode)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Country)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.City)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Owner.FirstName)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
            @Html.ActionLink("Details", "Details", new { id=item.Id }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.Id })

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

            <div class="CommentBox"></div>
            <span class="CommentAdd"></span>

            <span class="LinkSeparator"></span>
        </td>
        <td>
          <span id="flagMenus">
            @Html.Action("ShowFlag", "Flagging", new { entityId=item.Id, entityType="Location"})
         </span>
        </td>
    </tr>
}






</table>
</div> 

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

 </div>

<div style="float:left;width:100%;margin-top:30px;">
<div style="font-weight:bold;">All location Customers with open opportunities</div>
@Html.Action("AllLocationCustomersWithOpenOpprtunity", "Customer")
</div>



 <script type="text/javascript">

     $(document).ready(function () {

         $("a.pagenumber").click(function () {

             var page = 0;
             page = parseInt($(this).attr("id"));

             $.ajax({
                 url: '@Url.Action("GetPagedLocations")',
                 data: { "page": page },
                 success: function (data) 
                 { 
                 $("#LocationListPageWise").html(data);
                 }


             });
             return false;
         });

           $(document).ready(function () {

        $('.CommentBox').hide();

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


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

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

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

     });   

</script>
4

1 に答える 1

1

検索はそのような要素すべてに一致するため、ルート要素からコメントボックスを検索しないでください。次のようにクリックポイントから検索します。

$(document).ready(function () {

        $('.CommentBox').hide();

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


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

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

            $(this).closest('td').find('div.CommentBox').slideToggle();
            return false;
        });
});
于 2012-09-20T10:37:05.800 に答える