hi all,
ok what I am trying to achieve here is generate a list of objects and return to view like return View(list); list is List
Then in view I wanted to display this in table /grid but I have few problems
@model IEnumerable<myCodeProject.Models.bookModel>
@using Umbraco.Web
@using System.Web.Mvc.Html
@if (Umbraco.MemberIsLoggedOn())
{
<p>Books</p>
<table>
<tr>
<td>Ref No</td>
<td>Type</td>
<td>Name</td>
<td>Status</td>
<td>Details</td>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.refno</td>
<td>@item.type</td>
<td>@item.name</td>
<td>@item.status</td>
<td><a href="/books/book-details/?cno=" @item.id>View</a></td>
</tr>
}
</table>
}
else
{
Session.Add("NeedRedirect", Request.Url.ToString());
{ Html.RenderPartial("~/Views/Partials/myCodeProject/icLogin.cshtml", new myCodeProject.Models.icLoginModel(), new ViewDataDictionary { { "mymsg", "1" } }); }
}
then in macro partial I am calling my partial view - as i don’t want to create template for each feature
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using myCodeProject.Models
@{Html.RenderPartial("~/Views/Partials/myCodeProject/Listbooks.cshtml",new bookModel());}
in my controller I am generating book list from a third party service and return View (list)
problem 1. I get error MemberIsLoggedOn() is not list on Umbraco error.
if i take that if condition off to check my book listing
problem 2 I get error
the model item passed into the dictionary is of type ‘myCodeProject.Models.bookModel’, but this dictionary requires a model item of type ‘System.Collections.Generic.IEnumerable`1[myCodeProject.Models.bookModel]’.
that mean to use @model in my partial view I cannot call macropartial to render my view
not sure I am trying to aproach some this wrong here , I cannot add view to template other wise i’ll end up with adding too many templates .
I have noticed that when you call partial view from macro surfacecontroller not hit the Index() method either.
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/83868-how-to-use-model-in-partial-view-and-return-list-from-controller-to-view