在razor视图特定部分以编程方式添加代码 [英] Add code programmatically in razor view specific section
问题描述
我为asp.net MVC创建了一个HTMLHelper,它生成并在控件渲染时放入体内.bellow是代码示例结构
< div id =' someid' > < / div >
< span id =' spanid ' > < / span >
< ; script >
// 某些功能
< / script >
我想将脚本部分放在页面底部的部分。就像我有一个部分
< div id = ' someid' > < / div >
< ; span id < span class =code-keyword> =' spanid' > < / span >
@section scripts {
< script >
// 某些功能
< span class =code-keyword>< / script >
}
有可能以编程方式?代码示例将不胜感激。
我尝试过:
我想,如果ASP.Net MVC内置的方法是按名称找到一个部分那么
按名称查找部分
并将脚本附加到结尾
我用google搜索按名称查找部分,但遗憾的是没有找到任何内置的ASP.Net MVC代码。
检查这些
我可以在ASp.Net MVC中使用System.Web.UI.Page.ClientScript吗? - Stack Overflow [ ^ ]
MVC + ClientSCript.RegisterStartupSCript替代方案。 | ASP.NET论坛 [ ^ ]
I create a HTMLHelper for asp.net MVC which generate and ,and placed in body when control render .bellow is code sample structure
<div id='someid'></div>
<span id='spanid'></span>
<script>
//some function
</script>
I want to place the script part into section placed bottom of the page . Like I have a section
<div id='someid'></div>
<span id='spanid'></span>
@section scripts{
<script>
//some function
</script>
}
Is it possible programmatically?a code sample will be appreciated.
What I have tried:
I think,if is there way in ASP.Net MVC builtin to find a section by name then
Find section by name
and append script to end
I googled for finding section by name but unfortunately not found any builtin ASP.Net MVC code.
check these
Can i Use System.Web.UI.Page.ClientScript in ASp.Net MVC? - Stack Overflow[^]
MVC + ClientSCript.RegisterStartupSCript alternative. | The ASP.NET Forums[^]
这篇关于在razor视图特定部分以编程方式添加代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!