I don't quite understand why I can't use both strongly typed view and umbraco template in one view.
I have a script importing excel data. My website is in umbraco 7. I use Import.cshtml view which calls upload.cshtml partial
@inherits UmbracoTemplatePage
@{
Layout = "~/Views/Master.cshtml";
var locations = new List<SelectListItem>
{
new SelectListItem {Selected = false, Text = "location 1", Value = ""},
};
var fileTypes = new List<SelectListItem>
{
new SelectListItem {Selected = false, Text = "type 1", Value = ""},
};
}
<div id="page-bgtop">
<div class="post">
<h1>@Umbraco.Field("title")</h1>
<div class="entry">
@Html.Partial("Upload", new MvcImport.Models.ImportModel { FileTypes = fileTypes, Locations = locations })
</div>
</div>
<div class="clear"> </div>
</div>
Upload.cshtml partial does the job in ImportController. The data are there inserted into nicely into
List<CourseImport> courses = List<CourseImport>
All I want to do with it now is to display them in a view or partial view. I tried several things:
CASE 1
1.
in ImportController I do:
return View("CoursesList", courses);
2.
The view includes a table which displays the rows and starts with
@inherits UmbracoTemplatePage
@model IEnumerable<MvcImport.Models.CourseImport>
@{
Layout = "~/Views/Master.cshtml";
}
3.
In this case I get:
Parser Error Message: The 'inherits' keyword is not allowed when a 'model' keyword is used.
CASE 2
1.
As 1. in Case 1.
2.
The view starts with (so without @inherits UmbracoTemplatePage)
@model IEnumerable<MvcImport.Models.CourseImport>
@{
Layout = "~/Views/Master.cshtml";
}
3.
I get:
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[MvcImport.Models.CourseImport]', but this dictionary requires a model item of type 'Umbraco.Web.Models.RenderModel'.
CASE 3
1.
In ImportController I do
return PartialView("CoursesList", courses);
2.
I'm now using partial view which it similar to the view in the above points and also is strongly typed eg.
@model IEnumerable<MvcImport.Models.CourseImport>
3.
In this case the data is displayed but without my umbraco template shape, no styling etc.
If in the partial view I include
@{
Layout = "~/Views/Master.cshtml";
}
I get the same error as in Case 2
Changing the starting directive to
@model UmbracoViewPage<MvcImport.Models.CourseImport>
does not work either as the model must be enumerable
Can someone advise me how to do it? I guess there must be a solution but I am very new to MVC so I don't get how things work yet too much.
Thanks.
The solution is provided on umbraco forum website http://our.umbraco.org/forum/developers/razor/55389-UmbracoTemplatePage-and-strongly-typed-view-not-working-together?p=0