locked
two values are sent in the page .page no and AdvoFId.paging is not working. RRS feed

  • Question

  • User1493762548 posted

    if i comment out first line like in the code following error occur:

    Cannot perform runtime binding on a null reference

    Line 75:         <p>Page @page of @totalPages</p>

    if i comment out second line and uncomment first line the page viewForum works fine .but when next page is clicked the same above error.please help.

    here is the code for page.

        
       //var AdvoFId=Request["AdvoFId"];
       var AdvoFId= UrlData[1].AsInt(1);
        var db = Database.Open("PhotoGallery");
        
        var p= @"SELECT AdvoFId ,MessageHeader,MessageBody,AdvoName,newFileName FROM AdvoForum INNER JOIN Advocates
                                  ON AdvoForum.AdvoId =Advocates.AdvoId  where AdvoFId=@0 " +" ORDER BY AdvoForum.UpdateTime desc"; 
                   var forum = db.QuerySingle(p,AdvoFId) ;
     
        if (IsPost)
        {
            var Reply = Request["Reply"].Trim();
            
            if (Reply.IsEmpty()) 
            {
                Response.Redirect("~/Advocate/ViewForum/?AdvoFld=@AdvoFId");
            }
     
             
                 
         
        var UserId=WebSecurity.CurrentUserId;
                 
         
        var advo= db.QuerySingle("SELECT * FROM Advocates WHERE UserId = @0",UserId);
        var AdvoId=advo.AdvoId;
            db.Execute("INSERT INTO AdvoFReply ( Reply,AdvoId,AdvoFId,ReplyTime) VALUES (@0, @1, @2,@3)",
              Reply,AdvoId,AdvoFId,DateTime.Now);
                 }
                 
        var pageSize = 6; 
        var totalPages = 0; 
        var count = 0;
        var page = UrlData[0].AsInt(1);
       
        var offset = (page -1) * pageSize;
        
       
         var sql = @"Select Count(*) From AdvoFReply INNER JOIN Advocates
                                  ON AdvoFReply.AdvoId = Advocates.AdvoId where AdvoFReply.AdvoFId=@0 ";
                                  
                     count = (int)db.QueryValue(sql,AdvoFId);
        totalPages = (int)Math.Ceiling((double)count/pageSize); 
        
         sql = @"SELECT * FROM AdvoFReply INNER JOIN Advocates
                                  ON AdvoFReply.AdvoId =Advocates.AdvoId "+" where AdvoFReply.AdvoFId=@0" +" ORDER BY ReplyTime desc"+
                   " OFFSET @1 ROWS FETCH NEXT @2 ROWS  ONLY;";
                   
                  
                   var result = db.Query(sql,AdvoFId,offset, pageSize) ;
        
         
        }
     
    <div class="fluid">
        <div class="bg-info ">
            <p>Page @page of @totalPages</p> 
            
            <div class="bg-success">
            <form method="post" action="">
                <fieldset >
                    <legend> Reply To Message</legend>
                    <ol>
                        <li>
                            <label for="Reply">Reply:</label><br/>
                            <textarea  id=""name="Reply" title="Reply" rows="2" cols="70" placeholder="start writing here!"></textarea>
                        </li>
                        
                    </ol>
                    
                        <input type="submit" title="Add Post" value=" Post" />
                    
     
                </fieldset>
            </form>
       </div>
             <div class="media">
      <a class="media-left bg-warning" href="">
        <img class="media-object" src="~/AdvoPics/@forum.newFileName" alt="Profile picture">
          
      </a>
     <div class="media-body text-center text-danger ">
        <h4 class="media-heading text-center bg-warning">@forum.AdvoName &nbsp @forum.MessageHeader </h4>
       <p>@forum.MessageBody</p>
       
         </div>
    </div>
             
            
        @foreach(var row in result){
            <div class="media">
      <a class="media-left bg-warning" href="~/Advo/@row.AdvoId">
        <img class="media-object" src="~/AdvoPics/@row.newFileName" alt="Profile picture">
          
      </a>
     <div class="media-body text-center bg-success">
        <h4 class="media-heading text-center bg-warning"> @row.AdvoName</h4>
          @row.Reply
       <p><span class="glyphicon glyphicon-time"></span>&nbsp @row.UpdateTime.ToString("f")</p>&nbsp <br/>
        
         </div>
    </div>
             
            
     
     
        }
    </div>
     
     
    </div>
     
        
     
     
          
                      <br/> 
        @{
           
            for (var i = 1; i <= totalPages; i++){
                
                <a href="~/Advocate/ViewForum/@i?AdvoFld=@AdvoFId"><button class="btn-info">@i</button></a>
            }
        }
    <hr>
     <a href="~/Advocate/AdvoForum.cshtml"><button class="btn-success">Back</button></button></a>
     
    
    Sunday, July 10, 2016 4:44 AM

Answers

  • User1493762548 posted

    thanks all there was error in parameters var pag------ line.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 11, 2016 1:37 AM