简体   繁体   English

UmbracoTemplatePage和强类型视图不能一起使用

[英]UmbracoTemplatePage and strongly typed view not working together

I don't quite understand why I can't use both strongly typed view and umbraco template in one view. 我不太明白为什么我不能在一个视图中同时使用强类型视图和umbraco模板。

I have a script importing excel data. 我有一个导入Excel数据的脚本。 My website is in umbraco 7. I use Import.cshtml view which calls upload.cshtml partial 我的网站在umbraco 7中。我使用Import.cshtml视图,该视图调用upload.cshtml部分

@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. Upload.cshtml部分在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

1. 1。

in ImportController I do: 在ImportController中,我这样做:

return View("CoursesList", courses);

2. 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. 3。

In this case I get: 在这种情况下,我得到:

Parser Error Message: The 'inherits' keyword is not allowed when a 'model' keyword is used.

CASE 2 案例2

1. 1。

As 1. in Case 1. 如1。

2. 2。

The view starts with (so without @inherits UmbracoTemplatePage) 视图以(因此没有@inherits UmbracoTemplatePage)开头

@model IEnumerable<MvcImport.Models.CourseImport>
@{
    Layout = "~/Views/Master.cshtml";
}

3. 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 案例3

1. 1。

In ImportController I do 在ImportController中

return PartialView("CoursesList", courses);

2. 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. 3。

In this case the data is displayed but without my umbraco template shape, no styling etc. 在这种情况下,显示的数据没有我的umbraco模板形状,没有样式等。

If in the partial view I include 如果在局部视图中,我包括

@{
    Layout = "~/Views/Master.cshtml";
}

I get the same error as in Case 2 我遇到与案例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. 我猜必须要有解决方案,但是我对MVC还是很陌生,所以我还不太了解事情的运作方式。

Thanks. 谢谢。

该解决方案在umbraco论坛网站上提供: http: //our.umbraco.org/forum/developers/razor/55389-UmbracoTemplatePage-and-strongly-typed-view-not-working-together?p=0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM