我已将我的asp.net核心Web应用程序从1.0.1更新到1.1.0,但我的viewcomponents的标记帮助程序无效:
<vc:login-form />
输出标签。它使用旧语法:@await Component.InvokeAsync(typeof(LoginFormViewComponent))
的package.json:
{
"title": "DevPortal.Web",
"version": "0.1.0",
"language": "",
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.1.0",
"type": "platform"
},
"Microsoft.AspNetCore.StaticFiles": "1.1.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"Microsoft.AspNetCore.Mvc": "1.1.0",
"NuGet.CommandLine": "3.5.0",
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final"
},
"frameworks": {
"netcoreapp1.1": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"scripts": {
"prepublish": [ "bower install"],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
},
"userSecretsId": "aspnet-DevPortal.Web-20161230052130"
}
我已将此添加到_ViewImports.cshtml:
@addTagHelper "*, DevPortal"
我的程序集名称是DevPortal.dll
[ViewComponent(Name ="LoginForm")]
public class LoginFormViewComponent: ViewComponent
{
public IViewComponentResult Invoke(LoginFormViewModel model = null)
{
if (model == null) model = new LoginFormViewModel();
return View(model);
}
}
答案 0 :(得分:1)
在这种情况下,默认值参数也存在问题。我们在github上跟踪了此问题,但当前ViewComponents不能具有默认值的参数
这应该有效:
<vc:login-form model="null" />
答案 1 :(得分:1)
我有一个 ASP.NET Core 5.0 Web 应用程序。我遇到了同样的问题,但我解决了这个问题。
例如:
如果我的项目名称是 MyProject
并且我的视图组件位于 Components
文件夹,我将以下代码添加到 _ViewImport.cshtml
并且它对我有用
@addTagHelper *, MyProject
有关详细信息,您可以观看此视频:Kudvenkat - ASP NET Core view component tag helper