gpt4 book ai didi

c# - ASP.NET MVC : Member with the same signature already exists error

转载 作者:行者123 更新时间:2023-11-30 20:11:29 24 4
gpt4 key购买 nike

我有两个同名的 Controller 。一个带有 [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();
}

最佳答案

它们不能同名,因为正常的 C# 编译器规则重载具有完全相同的名称和签名。在第二次重载时使用 [ActionName] 属性:

[ActionName("AddCriteriaItem")]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SaveCriteriaItem(CriteriaItemAddFormCollection ciafc)

关于c# - ASP.NET MVC : Member with the same signature already exists error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3728327/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com