Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,
As you all know the @Html.Action returns MvcHtmlString, so can save the result in a variable.

I tried following
<script type="text/javascript">
        @{
            var strHTML = @Html.Action("About", "Home");
        }

        alert("@strHTML");

        $('#divAbout').html(@strHTML);
</script>


My above code is not working, neither the alert is working nor it is displayed inside the divAbout.

Any idea how to do the same.

Thanks in advance
Posted
Comments
Dilan Shaminda 30-Oct-14 5:53am    
does alert message shows returned string?
dhage.prashant01 30-Oct-14 5:59am    
I can see the result in the strHTML, but alert is not working
Dilan Shaminda 30-Oct-14 6:05am    
remove "" inside the alert();
alert(@strHTML);
dhage.prashant01 30-Oct-14 6:08am    
still alert is not displayed.
I think '@' is razor syntax, because of which the alert is not working.
any idea?
Dilan Shaminda 30-Oct-14 6:20am    
try it like this..iam not a Razor fan :D
remove @{ }

var strHTML = @Html.Action("About", "Home");
alert(strHTML);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900