Erwin1 Erwin1 - 1 day ago 5
HTML Question

Html.Action for Loading Partial View into <div id=>

On my dashboard I have the following div which works fine and when the page is loaded the action return a view

<div id="result1" class="col-xs-2 col-sm-4">
@Html.Action("index", "Gauge1", new { p1 = 2025, p2 = 8, p3 = 101 })
</div>


How can I load the view generated from the
@Html.Action
into the
<div id = "result1"
when
(document).ready
in JQuery?

I tried this but it is not working.

<script type="text/javascript">
$(document).ready(function(){
$('#result1').load(@(Html.Action("index", "Gauge1", new { p1 = 2025, p2 = 8, p3 = 101 })));
});
</script>

<div id="result1" class="col-xs-2 col-sm-4">
</div>

Answer

Please try this:

<script type="text/javascript"> 
     $(document).ready(function(){
     var url = "@(Html.Raw(Url.Action("index","Gauge1", new { p1=2025, p2=8,p3=101})))";
     $('#result1').load(url);
</script>

<div id="result1" class="col-xs-2 col-sm-4">
</div>
Comments