1
我正在重写Web窗体应用程序,作为练习来学习一些MVC技能。MVC LinkButton等价
我在原始应用程序上有多个LinkButtons,它们会回发并引发将数据重新绑定到数据网格的serverside事件。
E.g.
事件处理程序:
protected void lbtnOffset0_Click(object sender, EventArgs e)
{
Session["Offset"] = 0;
DataBind(); //this rebinds the data using the above argument
}
protected void lbtnOffset1_Click(object sender, EventArgs e)
{
Session["Offset"] = lbtnOffset1.Text;
DataBind(); //this rebinds the data using the above argument
}
我目前在MVC是这样的:
<%= Html.ActionLink("CurrentYr", "Index", 0)%>
<%= Html.ActionLink("1", "Index", 1)%>
和
public ActionResult Index()
{
return View(MietController.GetMietByYearOffset(0);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(int? offset)
{
int offsetValue = offset ?? 0;
return View(MietController.GetMietByYearOffset(offsetValue);
}
由于ActionLink的呈现它不是一个标签回发所以我重载的Index()方法不被调用。我在MVC中做这些的选择是什么?
看起来像你错过了“,”1和新的。 – 2010-02-04 15:22:17
@Nitin:谢谢。我修复了错字。 – tvanfosson 2010-02-04 16:04:40
这很有用,谢谢。我将研究AJAX ActionLinks。 – 2010-02-04 16:11:49