Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my code.

@helper CreateDiv()
{
<label>A</label>
}

<script type="text/javascript">
function SHowDiv()
{
alert('@Html.Raw(CreateDiv().ToString())');
}
</script>
<input type="button" value="ShowDiv" onclick="SHowDiv()" />





I want to show "A" inside div1 on button click. But it is giving me error. Where i am doing wrong? Please help. I have used alert just to check whether the button click is working or not.
Posted
Comments
Sergey Alexandrovich Kryukov 2-Jun-15 2:03am    
What is that "div1", where? In all cases, the problem is extremely simple.
What have you tried so far?
—SA

Hello,

Trim the output of the CreateDiv.ToString() by adding .Trim().

Your alert should be as below.

JavaScript
alert('@Html.Raw(CreateDiv().ToString().Trim())');


Happy Coding.!

Thank you,
RelicV
 
Share this answer
 
EASY SOLUTION:-

<script type="text/javascript">
function SHowDiv()
{
$('#Div1').html('A');
}
</script>
<input type="button" value="ShowDiv" onclick="SHowDiv()" />
 
Share this answer
 

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