我跟随location的Pluralsight课程,这似乎是当dotnetcore还没有打到RC2的时候,所以新指令的指示稍微偏离。
基本上我的剃刀观点没有成功地给我帮助智能,虽然帮助者自己正在工作保存asp-validation-summary
。
从预先构建的模板中,我可以看到识别出来的帮助者得到了自己的颜色:
但是在我从一个空项目开始并逐步完成的项目中,我得到以下内容:
正如您所看到的,我没有得到剃刀视图识别的帮助程序,尽管正确使用了帮助程序,如下所示:
<form>
<label for="Name">Name</label>
<input type="text" data-val="true" data-val-length="The field Name must be a string with a minimum length of 5 and a maximum length of 255." data-val-length-max="255" data-val-length-min="5" data-val-required="The Name field is required." id="Name" name="Name" value="" />
<span class="field-validation-valid" data-valmsg-for="Name" data-valmsg-replace="true"></span>
<label for="Email">Email</label>
<input type="email" data-val="true" data-val-email="The Email field is not a valid e-mail address." data-val-required="The Email field is required." id="Email" name="Email" value="" />
<span class="field-validation-valid" data-valmsg-for="Email" data-valmsg-replace="true"></span>
<label for="Message">Message</label>
<textarea cols="40" rows="4" data-val="true" data-val-length="The field Message must be a string with a minimum length of 5 and a maximum length of 1024." data-val-length-max="1024" data-val-length-min="5" data-val-required="The Message field is required." id="Message" name="Message">
</textarea>
<span class="field-validation-valid" data-valmsg-for="Message" data-valmsg-replace="true"></span>
<div>
<input type="submit" />
</div>
</form>
以上内容不包括我的屏幕截图中的一行:
<div asp-validation-summary="ValidationSummary.ModelOnly"></div>
因为只要我添加该行,页面就不会呈现。我收到500内部服务器错误。
以下是相关的一些内容,虽然可以让我的intellisense工作,但主要取自Github issue
Startup.cs
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
app.UseMvc(config =>
{
config.MapRoute(
name: "Default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "App", action = "Index" }
);
});
}
}
Project.json
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.0.0-preview1-final",
"type": "build"
}
},
"tools": {
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
_ViewImports.cshtml
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
请注意,我已经看到问题here,但这与(看似)不同的命名空间和不同的RC有关。链接的问题是dotnet,我使用的是dotnetcore和RC2。
有什么想法吗?问题的基本摘要:除了asp-validation-summary(到目前为止)之外,没有标签助手intellisense,虽然助手(大多数情况下)工作。
答案 0 :(得分:0)
这似乎是一个例子“你试过把它关掉再打开吗?”重新启动Visual Studio后,我的助手开始使用正确的颜色突出显示和智能感知。
此外,由于现在正确使用智能感知,我可以看到asp-validation-results
的语法与早期版本的核心略有不同。
<div asp-validation-summary="ValidationSummary.ModelOnly"></div>
现在需要:
<div asp-validation-summary="ModelOnly"></div>
答案 1 :(得分:0)
我设法通过从下面的链接重复相同的指令然后重新启动visual studio来解决问题。
https://github.com/aspnet/Tooling/issues/484#issuecomment-219807702