views:

30

answers:

3

Hi,

I have an Index view. On this view is a link, and it is created like this:

<%= Html.ActionLink("Clear All", "ClearAll", "CachedCollections") %>

I don't want to have a view for ClearAll, I just want it to go in the method, clear what it needs to clear and then post back to the Index view. How would I do this? Do I need to call a method for this?

EDIT:

Here is my code:

[HttpPost]
public ActionResult ClearAll()
{
   Debug.Print("Got to here");

   return RedirectToAction("Index", CachedDictionaryCollectionManager.List);
}

From my action link it's not hitting this action method. It just tells me that the resource is not found when I click on it.

Please advise.

Thanks.

+2  A: 

In your ClearAll method at the end just put:

return View("Index");

mattcodes
+1  A: 

Action methods don't really need to return anything:

Use: Return new EmptyResult();

Clicktricity
+2  A: 

in the called action you return RedirectToAction("Index");

public ActionResult ClearAll()
{
   ...
   return RedirectToAction("Index","Home");
   //Home is the controller name, don't specify it if you redirect to an action from the same controller
}
Omu
I've got this part, I've marked the method as HttpPost. When I click on the link then it says to me The resource cannot be found. I have a breakpoint in and it doesn't even go into the method.
Brendan Vogt
Please see updated comment.
Brendan Vogt
@Brendan Vogt it doesn't go there because a click on a link is not a post (usually), so you either remove the [HttpPost] or you put a form method="post" action="<%=Url("Action","Controller")%>" with a submit button instead of the Html.ActionLink
Omu