MVC 前台调用后台方法

例如:
View: <input type="submit" onclick="Sort(NewsType)" value="NewsType" id="NewsType" />
Controller:
public ActionResult Sort(string str)
{
//do something

return View(db.News.ToList());
}
我想在前台通过单击一个submit就调用后台的Sort()方法,应该怎么做?

第1个回答  推荐于2018-03-09
基于Razor视图引擎(MVC3以上)的写法。
View:
@using (Html.BeginForm("Sort", "YourControllerName"))
{
<input type="submit" value="NewsType" />
}
Controller的写法不变本回答被提问者和网友采纳
第2个回答  2013-04-02
建议你用路由,这也是mvc框架的一种实现机制,你可以再点击事件的时候用js截获,然后通过url触发具体的方法