开发者

How can i pass a single string to a partial View from an action that returns the partial view

开发者 https://www.devze.com 2022-12-21 06:50 出处:网络
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

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 jus开发者_Go百科t 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!


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消