views:

74

answers:

1

I am trying to learn MVC, and i'm creating threaded comments functionality for a simple webapp.

I have a view which lists the comments, and has a reply button that uses jQuery to load a partial view which is basically a comment form. I need to pass the parent commentId to the partial view and then populate the parentCommentId hiddenfield in the form so when posting it i can setup the correct relationship..

First off does this sound like the right approach? I've got the load working and the parentId is available to the 'ReturnCreateForm' action in the controller.. i'm just not sure how to pass it and read it in the partial view from the action. I've made a strongly typed partial view.. maybe not correct?

Thanks for any help!

A: 

I would probably just make the reply button insert/display the <form> using jQuery (that is, I would not do an AJAX call to render the partial view, I would just create the appropriate form using jQuery). At the same time I would add an input field (type=hidden) to the form. This input field would have the commentid as its value.

When the user submits the form use jQuery's $.ajax(...) method to do the POST, remove the <form> from the DOM and show a confirmation (or report an error).

Rune