【发布时间】:2015-01-26 18:43:25
【问题描述】:
我有一个小的 asp.net mvc 应用程序,其中我的 Index.html 中的操作链接很少,home controllder 中有以下代码。
当用户点击Edit ActionLink时,它会将控制权交给 HomerController 的“Edit”动作方法(类型为 httpGet)。该操作方法的视图是 Edit.cshtml。如果我在该 EDIT 视图中进行一些数据操作..并尝试发布该数据,我该怎么办?在同一个 HomeController 中编写另一个编辑操作方法(httpPost)?那样的话我家的控制器会变大吧?
如果我需要为此编写单独的控制器,如何将控制权转移到该控制器? (我的意思是如何将我新创建的编辑控制器附加到编辑视图?)
List<StateCity> stateCityList = new List<StateCity>();
public ActionResult Index()
{
StateCity sc1 = new StateCity() { Id = 1, StateName = "Dallas", Cities = new List<string>() { "ab", "cd" } };
StateCity sc2 = new StateCity() { Id = 2, StateName = "Austin", Cities = new List<string>() { "ef", "gh" } };
stateCityList.Add(sc1);
stateCityList.Add(sc2);
return View(stateCityList);
}
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
public ActionResult Edit(int id)
{
return View();
}
【问题讨论】:
标签: c# asp.net-mvc controller