【发布时间】:2011-04-13 07:14:36
【问题描述】:
我有两个同名的控制器。一个带有 [get],另一个带有 [post]。这两者执行完全不同的功能。为什么不能同名?
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult AddCriteriaItem(CriteriaItemAddFormCollection ciafc)
{
return View(ciafc);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AddCriteriaItem(CriteriaItemAddFormCollection ciafc)
{
string GroupName = (string)Session["SelectedGroupName"];
//add group or tab
switch (ciafc.CriteriaID)
{
case (int)enums.Criterias.Tab:
Template.AddTab(ciafc.TemplateID, ciafc.name, ciafc.description);
Response.Redirect(Server.UrlDecode(ciafc.rtn));
break;
case (int)enums.Criterias.Group:
Template.AddGroup(ciafc.TemplateID, ciafc.name, ciafc.description, ciafc.TabName);
ViewData["CategoryID"] = ciafc.CategoryID;
Response.Redirect(Server.UrlDecode(ciafc.rtn));
break;
default:
if (!string.IsNullOrEmpty(GroupName.ToString()) && ciafc.CriteriaID > 0 && !string.IsNullOrEmpty(ciafc.TabName))
{
Template.AddCriteriaItem(ciafc.TabName, GroupName, ciafc.name, ciafc.description, ciafc.options, ciafc.CriteriaID, ciafc.TemplateID);
}
ViewData["rtn"] = Server.UrlDecode(ciafc.rtn);
ViewData["TemplateID"] = ciafc.TemplateID;
ViewData["CategoryID"] = ciafc.CategoryID;
break;
}
Response.Redirect(Server.UrlDecode(ciafc.rtn));
return View();
}
【问题讨论】:
-
您真的需要 GET 版本吗?我的意思是,您似乎正在尝试将表单发布到 GET 方法,这实际上没有任何意义。你真的想让它做
return View(new CriteriaItemAddFormCollection())而不带参数吗? -
在这里发布了对类似问题的不同答案:stackoverflow.com/questions/6348372/…
标签: c# asp.net-mvc-2