Calling a method from a view
I have an Index view. On this view is a li开发者_如何转开发nk, 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.
In your ClearAll method at the end just put:
return View("Index");
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
}
Action methods don't really need to return anything:
Use: Return new EmptyResult();
精彩评论