English 中文(简体)
MVC 3 and the PartialView,scripts aren tprofile?
原标题:MVC 3 and the PartialViews, scripts aren t visible?

在我的拉伊特档案中(我使用Razak syntax),我列入了<编码>j。 书本图书馆

在我的部分意见中,我有<编码>jPaginate script Library和产生这一缩略语的代码。 问题在于,在这种情况下,不提供原始数据,而是如果我搬进<条码>。 书状图书馆在部分意见中发挥作用。 但是,我可以不改动<代码>j。 书状图书馆

So, how to access the scripts included in the Layout page in the PartialView ?

或者是否还有其他解决办法?


守则:

Layout.cshtml>

<head>
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
</head>

<body>
     @RenderBody()

     @RenderSection("Scripts", false)
</body>

MyView.cshtml>

@{ Html.RenderAction("SomeAction", "MyContoller"); } //it outputs the PartialView.vshtml

    @section Scripts {
        <script src="@Url.Content("~/Scripts/jquery.paginate.js")" type="text/javascript"></script>

        <script type="text/javascript">
            $(document).ready(function () {
                $("#pages").paginate({
                    count: 12,
                    start: 1,
                    display: 10,
                    border: false,
                    text_color:  #888 ,
                    background_color:  #EEE ,
                    text_hover_color:  black ,
                    background_hover_color:  #CFCFCF 
                });
            });
        </script>
    }

PartialView.cshtml

<link href="@Url.Content("~/Content/jpaginate.css")" rel="stylesheet" type="text/css" />

<div id="pages"></div>
最佳回答

贵格文在拉伊特做了什么? 它是否在结束布局? 如果是这样的话,当你把gin列入你的部分时, j就还没有界定。 我建议你在即将结束的您布局中确定一个章节,其中将载列习惯:

<body>
    ...
    ...
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    @RenderSection("Scripts", false)
</body>
</html>

而当时认为,使用这一部分(而不是部分部分,部分的斜线是处理任何文字,应当只打上标记)优先于本节,以包括这种观点所需要的任何缩略语:

@section Scripts {
    <script src="@Url.Content("~/Scripts/foo.js")" type="text/javascript"></script>
    <script type="text/javascript">
        // some inline script that uses the foo plugin
    </script>
}

This way all scripts that this page requires will get rendered at the end of the markup which is the recommended approach.

问题回答

If the script for jQuery is after the declaration for the Partial View you will get problems. I would recommend putting the jQuery script before the RenderBody.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.