Brendan Vogt
Brendan Vogt

Reputation: 26048

Calling a method from a view

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.

Upvotes: 2

Views: 136

Answers (3)

Omu
Omu

Reputation: 71288

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
}

Upvotes: 1

Clicktricity
Clicktricity

Reputation: 4209

Action methods don't really need to return anything:

Use: Return new EmptyResult();

Upvotes: 1

user53791
user53791

Reputation:

In your ClearAll method at the end just put:

return View("Index");

Upvotes: 2

Related Questions