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 178123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:10:34+00:00 2026-05-11T14:10:34+00:00

In asp.net mvc, I have been thinking it would be more advantageous to specify

  • 0

In asp.net mvc, I have been thinking it would be more advantageous to specify parametrized constructors on the view classes in contrast to using ViewData to pass data to the view. In this way the view class could be instantiated in the action and returned from there as an implementation of IView for eventual rendering to the client by the framework.

// An example of an action that returned one of two // views while passing a data objects from the current // scope. IView MyAction(discriminator){   if(discriminator){     return new MyView(SomeVal, SomeVal2)   }else{     return new AnotherView(SomeVal1)   } }  // An Example Definition for IView public interface IView{   Render(stream OutputStream); }  // An Example View Code Behind/Partial Class public partial class AnotherView{   public AnotherView(string GimmeData){     this.GimmeData = GimmeData   }    // This value could be accessed in the markup like:   // <%=this.GimmeData%>   public string GimmeData {get; set;} } 

I pose this question because I have personally found strongly typed views pointless as there is not 1 or 0 but n number of objects I would like to pass to the view from the action. I also find the ViewData collection a little too ‘untyped’ to mesh really well with the .net strongly typed world.

A parametrize constructor or even public properties on the view would allow the implementer of the view to specify a contract of what data is needed to render the view or can be rendered in the view. This approach would effectively encapsulate the view.

Why would this be a bad design? What advantages are provided with the ‘viewdata collection’/’strongly typed view’ ‘way’ of passing data from the action to the view. Does anyone think this would be a good idea?


update

I have had a change of heart. What I realized is that the view is really just about rendering. A very good design approach is to introduce Presentation Models that represent the user interfaces available in your application.

If something can be shown or not there should be a Boolean in your presentation model. If something can display text there should be a string for that in your presentation model. The presentation model is not anemic because you use it to encapsulate the logic of your UI. For example, if a field is empty then perhaps some other field is grayed out. This is presentation logic and it describes the way that your particular UI works.

Once a presentation model has been introduced the generic page classes work fine, you simply pass the view the correct presentation model. Presentation models allow you to clean up the code in your view as well as provide portability. If one decided to implement in winforms they would seriously only need to bind their UI to the presentation model.

Anyway, I just wanted to follow-up because I no longer agree with my original suggestion. I have accepted Travis’s answer because this is essentially what he proposed.

  • 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-11T14:10:35+00:00Added an answer on May 11, 2026 at 2:10 pm

    The convention is usually to provide a View Model that encapsulates the data you need in your view. You can then pass this strongly typed object down into your view. So, for example, you might have a BlogDisplay object that looks like this:

    public object BlogDisplayPage {   public string PageTitle {get; set;}   public BlogEntry Content {get; set;}   public IList<Comment> Comments {get; set;}   public IList<BlogEntry> RelatedEntries {get; set;}   public IList<BlogEntry> PreviousEntries {get; set;} } 

    Excuse the contrivedness of the example, but I think you understand what I’m trying to get at. This way, you can have all of the data associated with the View in one object that can be easily tested and maintained. This also has the advantage of having strongly typed Views using generics.

    I prefer this over your suggestion of parameterized constructors because its intent is clear, and the creation and aggregation of that data is going to be in one spot that will probably be easier to maintain.

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

Sidebar

Related Questions

I have been using telerik extensions for an asp.net mvc project, more specifically the
I have been working on a ASP.NET MVC 2 project and i've been thinking
For fields in my ASP.NET MVC view that have been attributed as required, is
I have been looking at many ASP.Net MVC client side validation ideas including xVal.
I have been developing an asp.net mvc application where i need to make large
I am trying to teach ASP.NET MVC to students (undergrads) that have been studying
I have been working my way through Scott Guthrie's excellent post on ASP.NET MVC
What is the best practice for submitting forms in ASP.NET MVC? I have been
I have a new ASP.NET MVC project (my first), and I had been running
I've been developing a site using ASP.NET MVC, and have decided to use the

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.