UmbracoTemplatePage和强类型的视图不合群 [英] UmbracoTemplatePage and strongly typed view not working together

查看:242
本文介绍了UmbracoTemplatePage和强类型的视图不合群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么我不能在一个视图中同时使用强类型的视图和一把umbraco模板。

I don't quite understand why I can't use both strongly typed view and umbraco template in one view.

我有一个脚本导入Excel数据。我的网站是一把umbraco 7。
我用它调用upload.cshtml部分

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部分确实在ImportController工作。这些数据有插入到能装进

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

在ImportController我做的:

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.


情形2


CASE 2

1

由于1案例1。

2

该视图开头(所以没有@inherits UmbracoTemplatePage)

The view starts with (so without @inherits UmbracoTemplatePage)

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

3。

我得到:

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'.


3 CASE


CASE 3

1

在ImportController我

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。

在这种情况下,数据被显示,但没有我的一把umbraco模板的形状,无定型等

In this case the data is displayed but without my umbraco template shape, no styling etc.

如果在局部视图我包括

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

我得到同样的错误在案例2

I get the same error as in Case 2

改变起始指令

@model UmbracoViewPage<MvcImport.Models.CourseImport>

不工作,无论是作为模型必须枚举

does not work either as the model must be enumerable

有人能告诉我该怎么办呢?我想必须有一个解决方案,但我很新的MVC所以我不明白事情是如何工作的又太多了。

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.

感谢。

推荐答案

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

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

这篇关于UmbracoTemplatePage和强类型的视图不合群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆