0

出于安全原因,我用剃刀在 ASP.NEt MVC4 中开发了一个应用程序,它定义了一个库 (dll) 一个帮助程序,以便在这个 dll 中为我们的 GUI 组件 (javascript/jquery) 充电。

在视图代码 index.cshtml 调用跟随助手(Html.ToolBarControl(“Person”)):

@using CrdToolBar;
@model MvcCrdToolBar.Models.Persona
@{
  ViewBag.Title = "Index";
}
<h2>Registro de Persona</h2>
@using (Html.ToolBarControl("Persona")) { }

查看页面代码时,我将其称为顶部的 javascript 函数,在需要此函数之前创建或添加之后有什么想法吗?

4

1 回答 1

1

If I understand you correctly you need to initialise some JS function/object before you call the Html.ToolbarControl helper? Couple of ways this can be done:

If you just want to have the JS inline then you can pretty much introduce it before you call it e.g.

<script type="text/javascript">

    // JS here

</script>
@using (Html.ToolBarControl("Persona")) { }

If you have a master layout, introduce a new section for the head which will allow you to inject JS directly from your index.cshtml page (by default MVC already does this for you)

Layer.cshtml

<head>
    @RenderSection("Head", false);
</head>

Index.cshtml

@using CrdToolBar;
@model MvcCrdToolBar.Models.Persona
@section Head {
    <script type="text/javascript">
        // JS here
    </script>
}
@{
     ViewBag.Title = "Index";
}

<h2>Registro de Persona</h2>
@using (Html.ToolBarControl("Persona")) { }
于 2012-11-27T16:32:49.150 回答