I know this would be easy for most of you folks, but I am new to this .net stuff. Trying to pass a list of string List to partial view, which is called with jquery load method
$('#tree-res').load("@Url.Action("GetTreeView" , "TreeView" )");
and i am calling this view from controller
public PartialViewResult GetTreeView()
{
List<string> list=new List<string>();
list.Add("Something");
return PartialView("TreeView",list);
}
Now, how to iterate over this list and display it in TreeView.cshtml
following throws errors :
@model List<string>
@foreach (var item in Model)
{
}
Thanks
Following is stack trace:
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
Line: 2
Stack Trace: [NullReferenceException: Object reference not set to an instance
of an object.] 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 context) +303
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.<>c_DisplayClass1c.b_19() +23
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +260 ....