3
這是我_Layout.cshtmlRenderSection和EditorForModel在asp.net MVC
<html>
<head>
@RenderSection("Script", false)
</head>
...
</html>
這是一個簡單的編輯頁面edit.cshtml
@model Shop.Models.Product
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@Html.EditorForModel()
,這是〜/查看/共享/ EditorTemplates /Product.cshtml
@model Shop.Models.Product
@section Script {
<script>alert("hello");</script>
}
...
@section Script{...}
不Product.cshtml工作,因爲EditorForModel的。怎麼辦?
只要把'@section腳本{...}'入'edit.cshtml'和所有其他視圖從您使用'Product.cshtml'。 – nemesv
@nemesv我知道,但我需要一個解決方案中使用'@section腳本{...}'在Product.cshtml –
它不會工作。 '@ section'只能在佈局和常規視圖中使用,所以它在部分視圖,編輯器或顯示模板中不受支持。我想你可以調整你的js的方式,它不會被要求從'Product.cshtml'包括... [編輯器中/顯示模板中使用的部分(指 – nemesv