TemplateEditor 中的 Tag Helper 不会根据 TemplateEditor 的位置进行绑定
Tag Helper in TemplateEditor doesn't bind depending on TemplateEditor's location
我正在使用区域来划分我的应用程序,并且一切都按预期工作,包括 EditorTemplate -- 但前提是编辑器模板位于特定位置。我的项目在这样设置时工作(注意 MyEditor.cshtml 的位置):
\Areas\Area1\Controllers\TestController.cs
\Areas\Area1\Views\Test\Index.cshtml
\Areas\Area1\Views\Shared\EditorTemplates\MyEditor.cshtml
我在 MyViewIndex.cshtml
中使用了一个 EditorTemplate (MyEditor.cshtml
),当我把它放在上面列出的位置时它工作正常。
然后我可以将 MyEditor.cshtml
移动到 MVC 找到它但不呈现标签助手的以下位置:
\Views\Shared\EditorTemplates\MyEditor.cshtml
所以这个标签助手...
<input asp-for="Hello1" type="text" />
...渲染如下:
<input value="ABC" type="text" id="Hello1" name="Hello1" />
...它像从未被处理过一样输出到浏览器:
<input asp-for="Hello1" type="text" />
在视图中 Index.cshtml 我有:
@Html.EditorFor(model => model.Hello1, "MyEditor")
里面MyEditor.cshtml我有:
Hello<br/>
@DateTime.Now<br/>
<input asp-for="OneEditorProperty1" type="text" />
我知道它正在寻找编辑器模板,因为它输出 "Hello" 并且我知道它在某种程度上正在处理它,因为我看到了 DateTime.Now 值。由于某种原因,Input Tag Helper 没有得到处理。
我的问题中缺少的是我的@addTagHelper 指令在哪里。
我这里有:
Areas\Area1\Views\_ViewImports.cshtml
但这里没有:
Views\_ViewImports.cshtml
我忘了我什至不得不拥有这个——感谢@dougbu 在 https://github.com/aspnet 指出这一点。
我正在使用区域来划分我的应用程序,并且一切都按预期工作,包括 EditorTemplate -- 但前提是编辑器模板位于特定位置。我的项目在这样设置时工作(注意 MyEditor.cshtml 的位置):
\Areas\Area1\Controllers\TestController.cs
\Areas\Area1\Views\Test\Index.cshtml
\Areas\Area1\Views\Shared\EditorTemplates\MyEditor.cshtml
我在 MyViewIndex.cshtml
中使用了一个 EditorTemplate (MyEditor.cshtml
),当我把它放在上面列出的位置时它工作正常。
然后我可以将 MyEditor.cshtml
移动到 MVC 找到它但不呈现标签助手的以下位置:
\Views\Shared\EditorTemplates\MyEditor.cshtml
所以这个标签助手...
<input asp-for="Hello1" type="text" />
...渲染如下:
<input value="ABC" type="text" id="Hello1" name="Hello1" />
...它像从未被处理过一样输出到浏览器:
<input asp-for="Hello1" type="text" />
在视图中 Index.cshtml 我有:
@Html.EditorFor(model => model.Hello1, "MyEditor")
里面MyEditor.cshtml我有:
Hello<br/>
@DateTime.Now<br/>
<input asp-for="OneEditorProperty1" type="text" />
我知道它正在寻找编辑器模板,因为它输出 "Hello" 并且我知道它在某种程度上正在处理它,因为我看到了 DateTime.Now 值。由于某种原因,Input Tag Helper 没有得到处理。
我的问题中缺少的是我的@addTagHelper 指令在哪里。
我这里有:
Areas\Area1\Views\_ViewImports.cshtml
但这里没有:
Views\_ViewImports.cshtml
我忘了我什至不得不拥有这个——感谢@dougbu 在 https://github.com/aspnet 指出这一点。