vijay yaragall
vijay yaragall

Reputation: 111

how to call a method in controller asynchronously in mvc3

I have to call the method in the controller from view, but not using any click, so I am thinking to do it using the following line of code:

@Html.RenderAction("Replies", new { id= item.ID})  

and my method in the controller is like this:

public post Replies(int Id)  
    {  
        post posts = new post();  
        posts = new Data_Access().Get_Replies(Id);   
        return posts;  
    }  

but this is showing error saying that "can not implicitly convert type void to object"
can any one please help me.. thanks

Upvotes: 0

Views: 461

Answers (1)

SLaks
SLaks

Reputation: 888185

RenderAction writes the result directly to the page and returns void.
@whatever writes the result of whatever to the page.

Since RenderAction doesn't return anything, it cannot be used in an @ block.

Instead, you should write @Html.Action(...).
Html.Action returns the result as an HelperResult object.

Upvotes: 1

Related Questions