Asp.net mvc 3 asp.net MVC中的RenderSection和EditorForModel
这是my_Layout.cshtmlAsp.net mvc 3 asp.net MVC中的RenderSection和EditorForModel,asp.net-mvc-3,Asp.net Mvc 3,这是my_Layout.cshtml <html> <head> @RenderSection("Script", false) </head> ... </html> 这是~/Views/Shared/EditorTemplates/Product.cshtml @model Shop.Models.Product @section Script { <script>alert("he
<html>
<head>
@RenderSection("Script", false)
</head>
...
</html>
这是~/Views/Shared/EditorTemplates/Product.cshtml
@model Shop.Models.Product
@section Script {
<script>alert("hello");</script>
}
...
@model Shop.Models.Product
@节脚本{
警惕(“你好”);
}
...
@section Script{…}
在Product.cshtml中不工作,因为EditorForModel。如何做到这一点?节仅在视图中工作,而不在部分中工作。编辑器模板是一种特殊的局部模板。无论如何,将javascript放在片段中是一种不好的做法,因此我只需在Edit.cshtml
视图中声明片段
但是如果你坚持把你的脚本放在标记的中间,因为RaRoR不支持分部中的部分,你可以实现它。只放<代码> @段脚本{…}进入
edit.cshtml
和使用Product.cshtml
@nemesv的其他视图。我知道,但我需要一个解决方案,在Product.cshtmlIt中使用@section Script{…}
<代码>@section仅允许在布局和常规视图中使用,因此在局部视图、编辑器或显示模板中不受支持。我认为您可以重新构造js,使其不必包含在Product.cshtml
…的可能副本中
@model Shop.Models.Product
@section Script {
<script>alert("hello");</script>
}
...