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

  • Home
  • SEARCH
  • 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 108161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:52:06+00:00 2026-05-11T01:52:06+00:00

Sometimes the overhead of creating a new model type is annoying. In these cases,

  • 0

Sometimes the overhead of creating a new model type is annoying. In these cases, I want to set ViewData, and the options seem to be:

  1. Simply set viewdata with a string key, and cast it out. This has obvious problems.

  2. Store the identifier (string key) somewhere (where? on the controller?) and cast it out on the viewpage. While solving one of the problems, I’m still casting, which is problematic, and kills type inference.

  3. Use the MVCContrib strongly typed Set/Get functions. These are nice sometimes, but if the type isn’t very descriptive, say a boolean ‘IsNew’, they don’t work too well. It also kills type inference and it’s still pretty much just doing a cast, so I must manually sync up the view and controller.

So, instead I’m thinking of using a phantom type to combine both the type and key identifier. It’d be equivalent to this psuedo-C#:

class ViewDataKey<T> = string 

This would let me create identifiers in the controller like this:

public static readonly ViewDataKey<bool> IsNew = 'IsNew'; 

With some simple extension methods, setting the data would be:

  ViewData.Set(IsNew, true); 

Getting it out is just as easy:

var isNew = ViewData.Get(FrobNozzleController.IsNew); 

Notice we don’t need to specify the type of isNew, it’s safely inferred. The key and type definitons are stored in one location.

Questions:

  1. Where should the key be stored? For ‘global-ish’ ViewData, some common class works fine. But for View/Controller specific data? Is there any downside to putting it on the controller? (Apart from the long name of the controller?)

  2. Are there any easier ways, or things already built-in?

  • 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-11T01:52:06+00:00Added an answer on May 11, 2026 at 1:52 am

    I think this is what the model does in the MVC pattern. Why you don’t use a typed view instead?

    I believe you just make things more complicated by introducing yet another dependency between the controller and the view. I don’t see any specific benefit in terms of line of code or something like that. You have to declare the existence of the variable, which you’d also do in the model class definition.

    You don’t get any significant advantage by doing so.

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

Sidebar

Ask A Question

Stats

  • Questions 59k
  • Answers 59k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I think you would see very negligible differences in performance.… May 11, 2026 at 9:02 am
  • added an answer As others answered, optparse is the best option, but if… May 11, 2026 at 9:02 am
  • added an answer You can use the MSI (Windows Installer) APIs to find… May 11, 2026 at 9:02 am

Related Questions

Sometimes the overhead of creating a new model type is annoying. In these cases,
In Java projects in Eclipse version 3.4.1 sometimes the folder Referenced Libraries disappears from
Unfortunately, sometimes the only way to debug a program is by going through its
I'm teaching myself some basic scraping and I've found that sometimes the URL's that
I have a web page that includes a bunch of images. Sometimes the image
I wish to search a database table on a nullable column. Sometimes the value
I am instantiating a local COM server using CoCreateInstance. Sometimes the application providing the
This is what I have so far: myArray.map!{ rand(max) } Obviously, however, sometimes the
I sometimes use the feature 'Reconcile Offline Work...' found in Perforce's P4V IDE to
When building a VS 2008 solution with 19 projects I sometimes get: The GenerateResource

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.