【问题标题】:HTML Helpers intellisense not working dotnetcore RC2HTML Helpers intellisense 不工作 dotnetcore RC2
【发布时间】:2016-06-05 15:01:19
【问题描述】:

我在 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 内部服务器错误。

以下是我本来可以让我的智能感知工作的相关位,主要来自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" }
                );
            });
        }
    }

项目.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(到目前为止)。

【问题讨论】:

    标签: c# razor asp.net-core asp.net-core-mvc


    【解决方案1】:

    这似乎是一个 ol 的案例“您是否尝试过将其关闭然后再打开?”重新启动 Visual Studio 后,我的助手开始使用正确的颜色突出显示和智能感知。

    此外,由于现在具有正确的智能感知功能,我可以看到 asp-validation-results 的语法与早期版本的核心略有不同。

    <div asp-validation-summary="ValidationSummary.ModelOnly"></div>
    

    现在需要:

    <div asp-validation-summary="ModelOnly"></div>
    

    【讨论】:

      【解决方案2】:

      我通过重复以下链接中的相同指令设法解决了这个问题,然后重新启动了 Visual Studio。

      https://github.com/aspnet/Tooling/issues/484#issuecomment-219807702

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-07-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-05
        • 2019-05-16
        • 2017-01-07
        相关资源
        最近更新 更多