• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

c# code in view

Integrating c# code in views

To integrity the C# code in a view we write the code complicity in source part of .asp x file by enclosing in server side decimeters’

<% C# code %>

2To write some C# code in index .asp x use the follows steps.

Go to solution explorer


Double click index.asp x from home folder of view


Go to source of index .asp x


Write the following code within the content place order




<% Response.write (‘welcome to MVC class’);%> <br/>

<% Response.write (Date.time.now.to string1);% > <br/>

<% for (int i=0; i<=10; i++)


Respons.write (“satya”);




Desired to gain proficiency on ASP.Net? Explore the blog post on ASP.Net training to become a pro in ASP.Net.

Example to create a view and calling in form browser

Go to solution explore


Go to select home folder from views


Click with RM button


Click on ADD


Click on view


Add view dialogue box will appear


Type the view name (sample)


Deactivate the check box select master page


Click on add


This will create a view with the name sample .asp x (no .cs file will be create)


Go to source


Write the following code


<h1>satya technologies</h>


2Any view will create is a class which is inherited from system.web.MVC.view page class.

To access this view from the web browser we can create an action method with the same name as view in home controller .cs file mandatorily.

Go to home controller .cs file


Write the following code

Public action result example ()


Return view ();


Run the application by default index page will appear to see the sample view you type in the address bar home/sample at the end of the address bar

http:// local host: 1974 (application name)/Home (control name)/sample (action method name)

For indepth understanding click on


Review Date
Reviewed Item
c# code in view
Author Rating

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on c# code in view"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Site Disclaimer, Copyright © 2016 - All Rights Reserved.


    Please leave a message and we'll get back to you soon.

    I agree to be contacted via e-mail.