Skip to content
Loading
call this helper in view
  1. class="row">  
  2. class="col-md-1">  
  3. @* A partial view. Sending the subset model to the partial view. *@  
  4. @Myhelper(Model.BlogPublishedByBlogId.LikeCount,Model.BlogPublishedByBlogId.DisLikeCount)  
  
  •   
  • +1
  • Laxmidhar Sahoo
    +1
    Hi
     
    May ViewDataDisctionary add the key value pair and send to partial view
     
    1. @models ViewDataDictionary  
    2. @{  
    3.     Model["LikeCount"] = 20;  
    4.      Model["DisLikeCount"] = 30;  
    5. }  
    6.   
    7.  @Html.Partial("_BlogLikeAndDislike", @Models)      
    Thanks and regards 
    +1
  • 0
    I created a class:
    1. namespace GbngWebClient.Models  
    2. {  
    3.     public class LikeOrDislikeVM  
    4.     {  
    5.         // Auto-implemented properties.  
    6.   
    7.         public int BlogId { get; set; }  
    8.         public int UserId { get; set; }  
    9.         public int LikeCount { get; set; }  
    10.         public int DisLikeCount { get; set; }  
    11.         public bool LikeDisabled { get; set; }  
    12.         public bool DisLikeDisabled { get; set; }  
    13.     }  
    14. }  
     
     
     
    I then used that class (a new model) in the parent view and populated it with values from the parent model and passed the model to the partial view : 
    1. @* Create a child 'model' variable (from the parent model's data) that will be passed to  the partial view. *@  
    2. @{  
    3.     // Create the variable form the LikeOrDislikeVM model.  
    4.     var likeOrDislikeVM = new GbngWebClient.Models.LikeOrDislikeVM();  
    5.   
    6.     // Set the properties on the variable.  
    7.     likeOrDislikeVM.BlogId = @Model.BlogPublishedByBlogId.BlogId;  
    8.     likeOrDislikeVM.UserId = Convert.ToInt32(Session["UserId"]);  
    9.     likeOrDislikeVM.LikeCount = @Model.BlogPublishedByBlogId.LikeCount;  
    10.     likeOrDislikeVM.DisLikeCount = @Model.BlogPublishedByBlogId.DisLikeCount;  
    11.     likeOrDislikeVM.LikeDisabled = @Model.BlogPublishedByBlogId.LikeDisabled;  
    12.     likeOrDislikeVM.DisLikeDisabled = @Model.BlogPublishedByBlogId.DisLikeDisabled;  
    13. }  
    14.   
    15. class="row">  
    16.     class="col-md-1">  
    17.         @Html.Partial("_BlogLikeAndDislike", likeOrDislikeVM)  
    18.     
      
  •   
  •  Then in the partial view, I called in the model: 
    1. @model GbngWebClient.Models.LikeOrDislikeVM  
    2.   
    3. @* Use the values that were passed via a model. *@  
    4. class="row">  
    5.     

      class="blogLike my-size fa fa-thumbs-up">class="my-size"> : @Model.LikeCount class="my-size"> | class="blogDisLike my-size fa fa-thumbs-down">class="my-size"> : @Model.DisLikeCount

        
      
    0