그래서 GridView에서 onRowCommand를 사용하여 데이터베이스에서 항목을 삭제하면 System.InvalidOperationException, 오류가 발생합니다. 문제는 그것이 완벽하게 작동하고, 항목을 삭제하지만, onRowCommand에 지정된 메소드가 끝나면 나에게 오류가 발생하는데, 이는 의미가 없습니다. '중 하나를 찾을 수 없거나 종류에 같은 이름을 가진 여러 방법이 있었다' '이름으로 공개 방법 ASP.admin_overview_aspx'OnRowCommand를 실행 한 후 이름이없는 System.InvalidOperationException (ASP.NET)
오류 보았다
여기
[InvalidOperationException: A public method with the name '' was either not found or there were multiple methods with the same name on the type 'ASP.admin_overview_aspx'.]
System.Web.UI.WebControls.ModelDataSourceView.FindMethod(String methodName) +2439378
System.Web.UI.WebControls.ModelDataSourceView.RequireAsyncModelBinding(String methodName, ModelDataSourceMethod& method) +67
System.Web.UI.WebControls.ModelDataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +86
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +930
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +1183
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +89
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +90
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +114
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +260
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639
protected void passwordGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridView gv = (GridView)sender;
int index = Convert.ToInt32(e.CommandArgument.ToString());
int id = Convert.ToInt32(gv.DataKeys[index].Value);
if (e.CommandName == "EDIT")
{
Response.Redirect("~/Admin,false);
}
else if (e.CommandName == "DELETE")
{
using (NubeSSPRContext db = new NubeSSPRContext())
{
var ppolicy = db.PasswordPolicies.Find(id);
db.Entry(ppolicy).State = EntityState.Deleted;
try
{
db.SaveChanges();
}
catch (DbUpdateConcurrencyException)
{
ModelState.AddModelError("",
String.Format("Item with id {0} no longer exists in the database.", id));
}
}
}
소스에 어떤 생각 : 여기
<h4>General Policies </h4>
<asp:GridView runat="server" ID="GeneralGrid"
ItemType="Source.GeneralPolicy" DataKeyNames="id"
SelectMethod="GPolicyGrid_Get"
AutoGenerateColumns="false" OnRowCommand="GeneralGrid_RowCommand">
<Columns>
<asp:DynamicField DataField="id" />
<asp:DynamicField DataField="name" />
<asp:DynamicField DataField="appliedGroup" />
<asp:DynamicField DataField="author" />
<asp:DynamicField DataField="createdOn" />
<asp:DynamicField DataField="modifiedOn" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="ButtonEdit" runat="server" CommandName="EDIT" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" Text="Edit" />
<asp:Button ID="ButtonDelete" runat="server" CommandName="DELETE" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" Text="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
및 1,363,210은 뒤에 코드인가? 다른 onRowCommand 메소드를 사용하여 삭제할 수있는 테이블이 4 개 있으며 삭제 후 모두 동일한 오류를 반환합니다.
미리 감사드립니다.
InvalidOperationException 뒤에 스택 추적을 게시 할 수 있습니까? –
@JoeIrby 예, 도움이되기를 바랍니다. – Enixf