tags:

views:

519

answers:

2

Hello.

I might have wandered into wrong direction so please help.

I have a page in my ASP.NET MVC application which displays comments. These comments come from 'Index' action of 'Comments' controller. At the bottom of the page I have a form for adding new comments. This form should call

[AcceptVerbs(HttpVerbs.Get)] 
public ActionResult AddComment();

action when rendering the form to user and

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult AddComment(Comment c);

action when posting new comment to server.

I presume that 'Comments' page should call three action methods (Index, AddComment[Get], AddComment[Post]). However AddComment[Get] is never called.

Please point me to right direction.

Thank you.

+1  A: 

If the form submit does a POST (submit) to the comments page (i.e. has the action of the comments page, and the method of POST), then it is indeed the POST version that chouls be used. The GET version would be used if you (for example) use a standard anchor/link to show the standalone comments page (or when issuing an AJAX "get" to that address).

How are you currently hitting the pages? At the moment it sounds like your index page is adding the form manually - so there is no place for the comments GET to be used, unless you are adding the form via AJAX.

Marc Gravell
Marc, The form submit should add comment and append it to the bottom (no ajax for now). The page html renders partial for each existing comment and after foreach loop there is a Html.BeginForm method. Thank you.
Valentin Vasiliev
If you mean via RenderPartial - that works at the "view" level; it never involves the controller...
Marc Gravell
A: 

Add a reference to the MVC Futures assembly, and use the Html.RenderAction helper method to include the result of another action in your page view.

Dave Van den Eynde