Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 122193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:05:24+00:00 2026-05-11T04:05:24+00:00

What is the purpose of the code behind view file in ASP.NET MVC besides

  • 0

What is the purpose of the code behind view file in ASP.NET MVC besides setting of the generic parameter of ViewPage ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T04:05:24+00:00Added an answer on May 11, 2026 at 4:05 am

    Here’s my list of reasons why code-behind can be useful taken from my own post. I’m sure there are many more.

    • Databinding legacy ASP.NET controls – if an alternative is not available or a temporary solution is needed.
    • View logic that requires recursion to create some kind of nested or hierarchical HTML.
    • View logic that uses temporary variables. I refuse to define local variables in my tag soup! I’d want them as properties on the view class at the very least.
    • Logic that is specific only to one view or model and does not belong to an HtmlHelper. As a side note I don’t think an HtmlHelper should know about any ‘Model’ classes. Its fine if it knows about the classes defined inside a model (such as IEnumerable, but I dont think for instance you should ever have an HtmlHelper that takes a ProductModel. HtmlHelper methods end up becoming visible from ALL your views when you type Html+dot and i really want to minimize this list as much as possible.
    • What if I want to write code that uses HtmlGenericControl and other classes in that namespace to generate my HTML in an object oriented way (or I have existing code that does that that I want to port).
    • What if I’m planning on using a different view engine in future. I might want to keep some of the logic aside from the tag soup to make it easier to reuse later.
    • What if I want to be able to rename my Model classes and have it automatically refactor my view without having to go to the view.aspx and change the class name.
    • What if I’m coordinating with an HTML designer who I don’t trust to not mess up the ‘tag soup’ and want to write anythin beyond very basic looping in the .aspx.cs file.
    • If you want to sort the data based upon the view’s default sort option. I really dont think the controller should be sorting data for you if you have multiple sorting options accessible only from the view.
    • You actually want to debug the view logic in code that actuallky looks like .cs and not HTML.
    • You want to write code that may be factored out later and reused elsewhere – you’re just not sure yet.
    • You want to prototype what may become a new HtmlHelper but you haven’t yet decided whether its generic enough or not to warrant creating an HtmlHelper. (basically same as previous point)
    • You want to create a helper method to render a partial view, but need to create a model for it by plucking data out of the main page’s view and creating a model for the partial control which is based on the current loop iteration.
    • You believe that programming complex logic IN A SINGLE FUNCTION is an out of date and unmaintainable practice.
    • You did it before RC1 and didn’t run into any problems !!

    Yes! Some views should not need codebehind at all.

    Yes! It sucks to get a stupid .designer file created in addition to .cs file.

    Yes! Its kind of annoying to get those little + signs next to each view.

    BUT – It’s really not that hard to NOT put data access logic in the code-behind.

    They are most certainly NOT evil.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For the purposes of this question, the code base is an ASP.NET website that
I want to set the name attribute for HiddenField control of ASP.NET from code
Is there a good code snippets application for Delphi or general purpose with IDE
What exactly is the purpose of the 'obj' directory in .NET?
I have some code that I am putting in the code-behind of a master
I am developing an ASP.NET web application at work, and I keep running into
I am working in ASP .net 2.0. I am a learner. I have a
Newb here. I am instantiating the class below from a Silverlight page's code-behind. I
can i have some general advice on converting a classic asp site to asp.net?
Just starting with ASP.NET and find it difficult to use the GridView. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.