Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display asp mvc C# code on browser but visual studio compile that code and get parse error? i want display code on browser like this web site. please help
thanks

What I have tried:

<figure>
    <figcaption>
        Demo Display Code on Browser
    </figcaption>
    <pre>
    <code>
    <h2>Post</h2>
@using (Html.BeginForm("Index", "Home" , FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
    <p>
        Title: @Html.TextBox("matatil");
    </p>
    <p>
 
        Tags: @Html.TextBox("metaKeys");
    </p>
    <p>
        Short Description: @Html.TextBox("metaDesc");
    </p>
    <p>
        Auther Name:@Html.TextBox("autharName");
    </p>
    <p>
         Page Contant:@Html.TextArea("Pagecntant");
             </p>
        </code>



Get error below
-----------------
Server Error in '/' Application.

Parser Error 
  Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

 Parser Error Message: The using block is missing a closing "}" character.  Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.


Source Error: 



Line 13:     <code>
Line 14:     <h2>Post</h2>
Line 15: @using (Html.BeginForm("Index", "Home" , FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
Line 16: {
Line 17:     <p>
  

 Source File:  /Views/Home/DemoDisplayCode.cshtml    Line:  15 


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.114.0 
Posted
Updated 23-Jul-18 6:35am

The problem is that the @ character tells Razor to compile the code. You need to escape it by using @@:
<figure>
    <figcaption>
        Demo Display Code on Browser
    </figcaption>
    <pre>
    <code>
    <h2>Post</h2>
@@using (Html.BeginForm("Index", "Home" , FormMethod.Post, new { @@class = "form-horizontal", role = "form" }))
{
    <p>
        Title: @@Html.TextBox("matatil");
    </p>
    <p>
 
        Tags: @@Html.TextBox("metaKeys");
    </p>
    <p>
        Short Description: @@Html.TextBox("metaDesc");
    </p>
    <p>
        Auther Name:@@Html.TextBox("autharName");
    </p>
    <p>
         Page Contant:@@Html.TextArea("Pagecntant");
             </p>
        </code>
 
Share this answer
 
Comments
Member 13921452 24-Jul-18 5:23am    
It is working well.
Thanks a lot
Richard Deeming
Read the error message: it's couldn't make it any clearer!
The using block is missing a closing "}" character.  Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
Now look at your code:
HTML
<code>
    <h2>Post</h2>
@using (Html.BeginForm("Index", "Home" , FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{ <<<<<---- Where is the closing "}" for this?
    <p>
        Title: @Html.TextBox("matatil");
    </p>
    <p>
 
        Tags: @Html.TextBox("metaKeys");
    </p>
    <p>
        Short Description: @Html.TextBox("metaDesc");
    </p>
    <p>
        Auther Name:@Html.TextBox("autharName");
    </p>
    <p>
         Page Contant:@Html.TextArea("Pagecntant");
             </p>
        </code>
 
Share this answer
 
Comments
Member 13921452 22-Jul-18 7:34am    
My problem is just that I want to show my code on the browser. The code should correct or incorrect, but should appear on the browser. Visual Studio does not have to compile. Just like code displays at codeproject.com.
OriginalGriff 22-Jul-18 7:44am    
Of course it has to compile! It's can't be run unless it does, C# is not an interpreted language. :laugh:

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