admin管理员组文章数量:1418113
I got an action result inside a controller and i need to display Modals from bootstrap-modal the problem is... .
ScriptManager.RegisterStartupScript
isn't working like in old asp
there is a solution to this? I'm new to mvc.
I got an action result inside a controller and i need to display Modals from bootstrap-modal the problem is... .
ScriptManager.RegisterStartupScript
isn't working like in old asp
there is a solution to this? I'm new to mvc.
Share Improve this question edited Oct 25, 2012 at 13:14 Milo asked Sep 17, 2012 at 16:02 MiloMilo 3181 gold badge6 silver badges15 bronze badges2 Answers
Reset to default 4Ok, the easiest solution for registering javascript from the controller was quite obvious, but frustrating for someone who's new to the pattern:
Using named sections we find a place for put the javascript
You can use [Named Sections][1].
_Layout.cshtml
<head>
<script type="text/javascript" src="@Url.Content("/Scripts/jquery-1.6.2.min.js)">
@RenderSection("JavaScript", required: false)
</head>
and this code for the view
_SomeView.cshtml
@section JavaScript
{
@Html.Raw(ViewBag.message)
}
and in the controller we return
ViewBag.message = @"<script type='text/javascript' language='javascript'>alert(""Hello World!"")</script>"; ;
In ASP.NET MVC scripts are not registered in controller actions. There's a separation between controllers and views. So you could directly put the script in the corresponding view:
本文标签: aspnet mvcexecute javascript function from controller in MVC 3Stack Overflow
版权声明:本文标题:asp.net mvc - execute javascript function from controller in MVC 3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745278059a2651293.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论