我知道对大多数人来说这很容易,但我对这个.net的东西不熟悉。 尝试将字符串List列表传递给部分视图,该视图使用jquery load方法
调用$('#tree-res').load("@Url.Action("GetTreeView" , "TreeView" )");
我正在从控制器
调用此视图public PartialViewResult GetTreeView()
{
List<string> list=new List<string>();
list.Add("Something");
return PartialView("TreeView",list);
}
现在,如何迭代此列表并在TreeView.cshtml中显示它
以下抛出错误:
@model List<string>
@foreach (var item in Model)
{
}
由于
以下是堆栈跟踪:
Line 1: @model List<string>
Line 2: @foreach (var item in Model)
Line 3: {
Line 4: }
Source File: c:\scm\branches\Quest\Views\TreeView\TreeView.cshtml
行:2
Stack Trace: [NullReferenceException: Object reference not set to an instance
一个物体。] ASP._Page_Views_treeview_TreeView_cshtml.Execute()in c:\ scm \ branches \ Quest \ Views \ TreeView \ TreeView.cshtml:2 System.Web.WebPages.WebPageBase.ExecutePageHierarchy()+ 207 System.Web.Mvc.WebViewPage.ExecutePageHierarchy()+81
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext,TextWriter writer,WebPageRenderingBase startPage)+88 System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer,Object instance)+220 System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext,TextWriter writer)+115 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext 上下文)+303
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext,ActionResult actionResult)+13
System.Web.Mvc&LT;&GT; C_ DisplayClass1c.b _19() 23
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter,ResultExecutingContext preContext,Func`1 continuation)+260 ....
答案 0 :(得分:0)
当然看起来你的模型是空的。自从GetTreeView
添加代码后,您确定已经重新编译了吗?