从视图中调用方法

时间:2010-10-04 11:19:58

标签: asp.net asp.net-mvc

我有一个索引视图。在这个视图上是一个链接,它是这样创建的:

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

我不想拥有ClearAll的视图,我只想让它进入方法,清除它需要清除的内容,然后回发到Index视图。我该怎么做?我需要为此调用一种方法吗?

编辑:

这是我的代码:

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

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

从我的操作链接中,它没有达到此操作方法。它只是告诉我,当我点击它时找不到资源。

请告知。

感谢。

3 个答案:

答案 0 :(得分:2)

最后在ClearAll方法中放入:

返回视图(“索引”);

答案 1 :(得分:1)

动作方法实际上不需要返回任何内容:

使用:Return new EmptyResult();

答案 2 :(得分:1)

在被调用的操作中,您返回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
}
相关问题