I'm new to the ASP.NET MVC 3 pattern and I want to call a JavaScript function in view (or controller), to display the result in a div or span object.
My solution
- I create a new ASP MVC3 Solution (using Razor)
- Add a new JavaScript in Script folder
Add a simple script function in the new JavaScript file, like this:
function HolaMundo(){ return "hola desde javascript"; }Add a reference from the JavaScript in the
index.csHTMLfile from my default controller.@section JavaScript { <script src="@Url.Content("~/Scripts/Maps.Helper.js")" type="text/javascript"> </script> }Finally add a call for the function:
<p> <div id="map_canvas2" style = "width:100%; height:100%"> result from Javascript </div> </p> <script type="text/javascript"> $(document).ready(function() { <text> $('#map_canvas2').text(HolaMundo()); </text> }); </script>
Result
Doesn't work
So, can any help me? I appreciate your help.