如何将指向JavaScript文件的链接添加到ASP.NETMVC页面的标题Howtoaddalinkto将JavaScript文件添加到ASP.NETMVC页面的页眉?假设有_Layout.cshtml和About.cshtml,我需要将一些javascript文件放入About.cshtml的标头中。我只是说那个页面。http://www.dotnetcurry.com/ShowArticle.aspx?ID=636怎么做?为什么它必须在标题中?你可以包含任何你需要的内联脚本:MySolution_Layout.cshtml!DOCTYPEhtml>@ViewBag.Title@if(IsSectionDefined("AddToHead")){@RenderSection("AddToHead",required:false)}About.cshtml@{ViewBag.Title="索引";}Index@sectionfooter{FooterHere}@sectionAddToHead{}试试下面的代码HtmlGenericControlmy_js=newHtmlGenericControl("script");my_js.Attributes["async"]="async";my_js.Attributes["type"]="text/javascript";my_js.Attributes["src"]="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js";Page.Header.Controls.Add(my_js);您需要使用命名空间:“使用System.Web.UI.HtmlControls”才能使用HtmlGenericControl。以上就是C#学习教程:如何在ASP.NETMVC页面的标题中添加一个JavaScript文件的链接。如果对你有用,需要进一步了解C#学习教程,希望大家多加关注——本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
