在 Razor 中调用局部视图
Calling Partial Views in Razor
我有一个问题似乎快把我逼疯了。如何将另一个母版的部分视图拉到我的主页(与视图等无关)并且在另一个文件夹中?我只想参考:
@Html.ThemedPartial(Model, "Latest")
(来自 Umbraco 中的 Articulate 博客)。但是,我不确定该怎么做,因为我不知道要包含哪些 using 指令等?
有没有简单的方法来做到这一点?
我收到以下错误:
Compiler Error Message: CS1061: 'System.Web.Mvc.HtmlHelper>' does not contain a definition for 'ThemedPartial' and no extension method 'ThemedPartial' accepting a first argument of type 'System.Web.Mvc.HtmlHelper>' could be found (are you missing a using directive or an assembly reference?)
它在 @Html.ThemedPartial(Model, "Latest")
引用源错误
我也试过 @Html.Partial("~/App_Plugins/Articulate/Themes/MyTheme/Views/Partials/Latest.cshtml", Model)
而不是 @Html.ThemedPartial(Model, "Latest")
但没有成功。我得到以下信息:
Umbraco.Web.Mvc.ModelBindingException: Cannot bind source content type Umbraco.Web.PublishedContentModels.Index to model type Articulate.Models.IMasterModel.
当您查看 Articulate sourcecode 时,您会发现 ThemedPartial 只是一个执行以下操作的扩展方法:
var path = PathHelper.GetThemePartialViewPath(model, partialName);
return html.Partial(path, viewModel, viewData);
其中 GetThemePartialViewPath returns 视图的相对路径
如果您正确设置了 Latest.cshtml 的 @model 声明,下面的内容应该可以工作
@Html.Partial("~/App_Plugins/Articulate/Themes/MyTheme/Views/Partials/Latest.cshtml", Model)
我想通了:
@Html.Partial("~/Views/Partials/Recent.cshtml", Model)
我有一个问题似乎快把我逼疯了。如何将另一个母版的部分视图拉到我的主页(与视图等无关)并且在另一个文件夹中?我只想参考:
@Html.ThemedPartial(Model, "Latest")
(来自 Umbraco 中的 Articulate 博客)。但是,我不确定该怎么做,因为我不知道要包含哪些 using 指令等?
有没有简单的方法来做到这一点?
我收到以下错误:
Compiler Error Message: CS1061: 'System.Web.Mvc.HtmlHelper>' does not contain a definition for 'ThemedPartial' and no extension method 'ThemedPartial' accepting a first argument of type 'System.Web.Mvc.HtmlHelper>' could be found (are you missing a using directive or an assembly reference?)
它在 @Html.ThemedPartial(Model, "Latest")
我也试过 @Html.Partial("~/App_Plugins/Articulate/Themes/MyTheme/Views/Partials/Latest.cshtml", Model)
而不是 @Html.ThemedPartial(Model, "Latest")
但没有成功。我得到以下信息:
Umbraco.Web.Mvc.ModelBindingException: Cannot bind source content type Umbraco.Web.PublishedContentModels.Index to model type Articulate.Models.IMasterModel.
当您查看 Articulate sourcecode 时,您会发现 ThemedPartial 只是一个执行以下操作的扩展方法:
var path = PathHelper.GetThemePartialViewPath(model, partialName);
return html.Partial(path, viewModel, viewData);
其中 GetThemePartialViewPath returns 视图的相对路径
如果您正确设置了 Latest.cshtml 的 @model 声明,下面的内容应该可以工作
@Html.Partial("~/App_Plugins/Articulate/Themes/MyTheme/Views/Partials/Latest.cshtml", Model)
我想通了:
@Html.Partial("~/Views/Partials/Recent.cshtml", Model)