Add form in View at runtime

Ismael123

Member
Joined
May 13, 2016
Messages
14
Programming Experience
1-3
i want a form containing a text bar to appear when comment is clicked
HTML:
 <li><a href="#" id="comment">Comment</a></li>

I couldnt do it using razor so I tried writing a Jquery script
HTML:
<script type="text/javascript">    
    $('#comment').click(function () {   
         $('div#txtcmd').html         
       (@using (Html.BeginForm("comment", "post"))   
             {                  
  @Html.TextArea("Comment")       
         }               
 )});
 </script>
I dont know jquery by the way, I just wrote this by researching. What am I doing wrong? Is there another way to get it done? Thanks in advance
 
Thanks, it worked. Here is the solution.
here is the link
HTML:
<li id="comment"><a href="#">Comment</a></li>

then the form
HTML:
 <div id="txtcomd" style="display:none">     
           @using (Html.BeginForm("comment", "post"))    
          {          
            @Html.TextArea("Comment") 
            <input type="submit" value="Commenter" />               
 } </div>

and lastly the script
HTML:
 <script type="text/javascript">       
 $(document).ready(function () {        
    $('#comment a').click(function () {           
       $('#txtcomd').toggle()      
      });      
  });    </script>
 
Back
Top Bottom