Skip to content
Loading
Asp.net partial view in a view not being recognized from within a view    
  •                 
  •     
  •             class="row">    
  •                 
        
  •                     @Html.DisplayFor(model => model.BlogPublishedByBlogId.BlogContent, new { @class = "form-control blogContent", @disabled = "disabled" })    
  •                     
  •                 
  •                 
  •     
  •             class="row">    
  •                 
        
  •                     @Html.Partial("_BlogLikeOrDislike")    
  •                     
  •                 
  •                 
  •     
  •             class="panel-footer">    
  •                 "button" class="btn btn-primary Comment" data-id="@Model.BlogPublishedByBlogId.BlogId" value="Comment">    
  •                     class="glyphicon glyphicon-comment" aria-hidden="true"> Get Comment(s)    
  •                     
  •                 
  •     
  •             @* The area dynamically built. It will hold the partial view - BlogPublished/_Comments.cshtml which also holds the partial view - BlogPublished/_CommentReplys.cshtml. *@    
  •             @* The partial view is shown after the 'Get Comment(s)' button above is clicked. *@    
  •     
  •             @* Add comment area. *@    
  •             "@string.Format("{0}_{1}","commentsBlock", @Model.BlogPublishedByBlogId.BlogId)" style="border: 1px solid #f1eaea; background-color: #eaf2ff;">    
  •                 @*Centering the button with in-line CSS. *@    
  •                 class="AddCommentArea" style="margin-left: 30%;  margin-bottom: 5px; margin-top: 8px;">    
  •                     @Html.AntiForgeryToken()    
  •                     "text" id="@string.Format("{0}_{1}", "comment", @Model.BlogPublishedByBlogId.BlogId)" class="form-control" placeholder="Add a comment..." style="display: inline;" />    
  •                     @* Button. *@    
  •                     "button" class="btn btn-primary addComment" data-id="@Model.BlogPublishedByBlogId.BlogId">class="glyphicon glyphicon-comment" aria-hidden="true">    
  •                     
  •                 
  •             
  •         
  • }    
  •     
  • @Scripts.Render("~/bundles/jqueryval")    
  • @Scripts.Render("~/bundles/jquery")    
  • @Scripts.Render("~/bundles/bootstrap")    
  • @Styles.Render("~/Content/css")    
  •     
  •     
  • @section Scripts    
  • {    
  •     "text/javascript">    
  •         $(document).ready(function () {    
  •             // Has ajax calls to controller methods.    
  •          });    
  •         
  • }  
  • --- The small partial view - _BlogLikeOrDislike.cshtml.
    1.     
    2.     "#" class="LikeOrDislike" style="margin-left: 5px; font-weight: bold; font-size: 13px;">Like    
        
  •     
  • @Scripts.Render("~/bundles/jqueryval")    
  • @Scripts.Render("~/bundles/jquery")    
  • @Scripts.Render("~/bundles/bootstrap")    
  • @Styles.Render("~/Content/css")    
  •     
  •     
  • @section Scripts    
  • {    
  •     "text/javascript">    
  •         $(document).ready(function () {    
  •             alert('here.');    
  •             console.log('here.');    
  •     
  •             $('.LikeOrDislike').on('click'function () {    
  •                 // HOW TO REFERENCE THE PARENTS VALUE?.    
  •                 var blogId = $(this).attr("data-id");    
  •     
  •                 alert('here. blogid from parent: ' + blogId);    
  •     
  •                 $.ajax({    
  •                     type: 'GET',    
  •                     url: '@Url.Action("SetBlogLikeCountOrDislikeCount", "BlogPublished")',    
  •                     data: { blogId: blogId },    
  •                     success: function (response) {    
  •     
  •                     },    
  •                     error: function (xhr, ajaxOptions, thrownError) {    
  •                         alert("Critical Error: something is wrong in the call to SetBlogLikeCountOrDislikeCount! Status: " + xhr.status + ". Error: " + thrownError.toString() + ". Response Text: " + xhr.responseText);    
  •                     }    
  •                 })    
  •             });    
  •         });    
  •         
  • }
  • 6 Replies

    Know the answer? Post it — somebody with the same question will find it here.