Sql 使用数据库中的标记列表索引越界异常
在编辑中尝试向视频添加标记时,似乎无法理解标记列表为何出现越界异常。我认为ilist会在需要时自动为某个项目创建一个新位置。。。标签应该与给定的视频相关联;因此,它应该生成一个新标签并与视频关联。但是,我有点搞砸了,比如使用Session.merge而不是Session.save,这样会生成一个新视频,而不是一个新标签。。。但保留标记[i].tagdescription不变会生成outofbounds异常。我相信答案是显而易见的,但我还是想不起来 编辑视图Sql 使用数据库中的标记列表索引越界异常,sql,nhibernate,indexoutofboundsexception,ilist,Sql,Nhibernate,Indexoutofboundsexception,Ilist,在编辑中尝试向视频添加标记时,似乎无法理解标记列表为何出现越界异常。我认为ilist会在需要时自动为某个项目创建一个新位置。。。标签应该与给定的视频相关联;因此,它应该生成一个新标签并与视频关联。但是,我有点搞砸了,比如使用Session.merge而不是Session.save,这样会生成一个新视频,而不是一个新标签。。。但保留标记[i].tagdescription不变会生成outofbounds异常。我相信答案是显而易见的,但我还是想不起来 编辑视图 @model PatientEduca
@model PatientEducationAdmin.Models.Domain.Video
@{
ViewBag.Title = "Edit";
}
@*putting black outline on text boxes*@
@*editors location*@
<div id="div8class" style="background-color: beige; width: 936px; border-bottom-left-radius: 15px; border-bottom-right-radius: 15px">
<h2>Edit</h2>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
@*edit for tags*@
<div class="editor-field">
<table style="text-align: center; align-content: center; float: none; margin: 10px auto; width: 500px;">
<tr>
<th>@Html.DisplayNameFor(model => model.Tags[0].TagID)</th>
<th>@Html.DisplayNameFor(model => model.Tags)</th>
</tr>
@{int i = 0;}
@using PatientEducationAdmin.Models.DAL.Repositories
@{ TagRepository tagDB = new TagRepository();}
@foreach (var item in Model.Tags)
{
<tr>
<td>
@Html.TextBoxFor(modelitem => item.TagID, new { @readonly = "readonly" })
</td>
<td>
@Html.TextBoxFor(modelItem => item.TagDescription, new { @readonly = "readonly" })
</td>
<td>
<button type="button" onclick="delTag()">Delete</button>
@*want a button to delete a specific tag or disassociate it from video...*@
</td>
</tr>
<tr>
@{i++;}
</tr>
}
</table>
<div class="editor-field">
@Html.EditorFor(model => model.Tags[i], new { id = "tagadd" })
<button>Add Tag</button>
</div>
</div>
<p>
<input type="submit" value="Save" />
</p>
}
<div>
@Html.ActionLink("Back to List", "SearchVideos")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
</div>
调用堆栈
mscorlib.dll!System.ThrowHelper.ThrowArgumentOutOfRangeException() + 0x49 bytes
mscorlib.dll!System.Collections.Generic.List.this[int].get(int index=1)+0x23字节
NHibernate.dll!NHibernate.Collection.Generic.PersistentGenericBag<PatientEducationAdmin.Models.Domain.Tag>.System.Collections.Generic.IList<T>.get_Item(int index = 1) + 0x87 bytes
[Lightweight Function]
System.Web.Mvc.dll!System.Web.Mvc.ExpressionUtil.CachedExpressionCompiler.Compiler<PatientEducationAdmin.Models.Domain.Video,PatientEducationAdmin.Models.Domain.Tag>.CompileFromFingerprint.AnonymousMethod__4(PatientEducationAdmin.Models.Domain.Video model = {PatientEducationAdmin.Models.Domain.Video}) + 0x42 bytes
System.Web.Mvc.dll!System.Web.Mvc.ModelMetadata.FromLambdaExpression<PatientEducationAdmin.Models.Domain.Video,PatientEducationAdmin.Models.Domain.Tag>.AnonymousMethod__2() + 0x88 bytes
System.Web.Mvc.dll!System.Web.Mvc.ModelMetadata.Model.get() + 0x3c bytes
NHibernate.dll!NHibernate.Collection.Generic.PersistentGenericBag.System.Collections.Generic.IList.get_项(int index=1)+0x87字节
[轻量级功能]
System.Web.Mvc.dll!System.Web.Mvc.ExpressionUtil.CachedExpressionCompiler.Compiler.CompileFromFingerprint.AnonymousMethod_uu4(PatientEducationAdmin.Models.Domain.Video model={PatientEducationAdmin.Models.Domain.Video})+0x42字节
System.Web.Mvc.dll!System.Web.Mvc.ModelMetadata.FromLambdaExpression.AnonymousMethod__2()+0x88字节
System.Web.Mvc.dll!System.Web.Mvc.ModelMetadata.Model.get()+0x3c字节
System.Web.Mvc.dll!System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(System.Web.Mvc.HtmlHelper Html={System.Web.Mvc.HtmlHelper}
System.Web.Mvc.ModelMetadata metadata={System.Web.Mvc.CachedDataAnnotationsModelMetadata},字符串htmlFieldName=“Tags[1]”,字符串templateName=null,System.Web.UI.WebControl.DataboundControls mode=Edit,对象additionalViewData={id=“tagadd”}
System.Web.Mvc.Html.TemplateHelpers.ExecuteTemplateDelegate executeTemplate={Method={System.Reflection.RuntimeMethodInfo}}})+0x94字节System.Web.Mvc.dll!System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(System.Web.Mvc.HtmlHelper Html={System.Web.Mvc.HtmlHelper},System.Web.Mvc.ModelMetadata元数据={System.Web.Mvc.CachedDataAnnotationsModelMetadata},字符串htmlFieldName=“Tags[1]”,string templateName=null,System.Web.UI.WebControls.DataBoundControlMode=Edit,object additionalViewData={id=“tagadd”})+0x5f字节
System.Web.Mvc.dll!System.Web.Mvc.Html.TemplateHelpers.TemplateFor(System.Web.Mvc.HtmlHelper Html={System.Web.Mvc.HtmlHelper} System.Linq.Expressions.Expression>Expression={System.Linq.Expressions.Expression>},string templateName=null,string htmlFieldName=null,System.Web.UI.WebControl.DataBoundControlMode=Edit,object additionalViewData={id=“tagadd”} System.Web.Mvc.Html.TemplateHelpers.TemplateHelperDelegate templateHelper={Method={System.Reflection.RuntimeMethodInfo}})+0xe4字节
System.Web.Mvc.dll!System.Web.Mvc.Html.TemplateHelpers.TemplateFor(System.Web.Mvc.HtmlHelper Html={System.Web.Mvc.HtmlHelper} System.Linq.Expressions.Expression>Expression={System.Linq.Expressions.Expression>},string templateName=null,string htmlFieldName=null,System.Web.UI.WebControls.DataBoundControlMode=Edit,object additionalViewData={id=“tagadd”})+0x8d字节
System.Web.Mvc.dll!System.Web.Mvc.Html.EditorExtensions.EditorFor(System.Web.Mvc.HtmlHelper Html={System.Web.Mvc.HtmlHelper} System.Linq.Expressions.Expression>Expression={System.Linq.Expressions.Expression>},对象additionalViewData={id=“tagadd”})+0x5e字节 App\u Web\u gfall1nh.dll!ASP.\页面\视图\视频\编辑\ cshtml.Execute()行138+0x27b字节C# System.Web.WebPages.dll!System.Web.WebPages.WebPageBase.ExecutePageHierarchy()+0xc6字节 System.Web.Mvc.dll!System.Web.Mvc.WebViewPage.ExecutePageHierarchy()+0x78字节
System.Web.WebPages.dll!System.Web.WebPages.StartPage.RunPage()+0x12字节
System.Web.WebPages.dll!System.Web.WebPages.StartPage.ExecutePageHierarchy()+0x3f字节
System.Web.WebPages.dll!System.Web.WebPages.WebPageBase.ExecutePageHierarchy(System.Web.WebPages.WebPageContext pageContext,System.IO.TextWriter writer,System.Web.WebPages.WebPageRenderingBase startPage)+0x4d字节
System.Web.Mvc.dll!System.Web.Mvc.RazorView.RenderView(System.Web.Mvc.ViewContext ViewContext={System.Web.Mvc.ViewContext},System.IO.TextWriter writer={System.Web.HttpWriter},对象实例={ASP.\U页面\视图\视频\编辑\ cshtml})+0x2e8字节
System.Web.Mvc.dll!System.Web.Mvc.BuildManagerCompiledView.Render(System.Web.Mvc.ViewContext ViewContext={System.Web.Mvc.ViewContext},System.IO.TextWriter writer={System.Web.HttpWriter})+0x17f字节
System.Web.Mvc.dll!System.Web.Mvc.ViewResultBase.ExecuterResult(System.Web.Mvc.ControllerContext上下文={System.Web.Mvc.ControllerContext})+0x1b0字节 System.Web.Mvc.dll!System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(System.Web.Mvc.ControllerContext ControllerContext={System.Web.Mvc.ControllerContext},System.Web.Mvc.ActionResult ActionResult={System.Web.Mvc.ViewResult})+0x28字节
System.Web.Mvc.dll!System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters.AnonymousMethod_17()+0x4b字节
System.Web.Mvc.dll!System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(System.Web.Mvc.IResultFilter={PatientEducationAdmin.Controllers.VideoController},System.Web.Mvc.ResultExecutionContext前文本={System.Web.Mvc.ResultExecutionContext},System.Func continuation={Method={System.Reflection.RuntimeMethodInfo})+0xb2字节
System.Web.Mvc.dll!System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters.AnonymousMethod_19()+0x49字节
System.Web.Mvc.dll!System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(System.Web.Mvc.ControllerContext ControllerContext=
NHibernate.dll!NHibernate.Collection.Generic.PersistentGenericBag<PatientEducationAdmin.Models.Domain.Tag>.System.Collections.Generic.IList<T>.get_Item(int index = 1) + 0x87 bytes
[Lightweight Function]
System.Web.Mvc.dll!System.Web.Mvc.ExpressionUtil.CachedExpressionCompiler.Compiler<PatientEducationAdmin.Models.Domain.Video,PatientEducationAdmin.Models.Domain.Tag>.CompileFromFingerprint.AnonymousMethod__4(PatientEducationAdmin.Models.Domain.Video model = {PatientEducationAdmin.Models.Domain.Video}) + 0x42 bytes
System.Web.Mvc.dll!System.Web.Mvc.ModelMetadata.FromLambdaExpression<PatientEducationAdmin.Models.Domain.Video,PatientEducationAdmin.Models.Domain.Tag>.AnonymousMethod__2() + 0x88 bytes
System.Web.Mvc.dll!System.Web.Mvc.ModelMetadata.Model.get() + 0x3c bytes
@Model.Tags.Add(new Tag());
@Html.EditorFor(model => model.Tags[i], new { id = "tagadd" })