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

The Archive Base Latest Questions

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

There’s no strongly typed View() method to return an ActionResult. So, suppose I have

  • 0

There’s no strongly typed View() method to return an ActionResult. So, suppose I have

class Edit : ViewPage<Frob> 

In my FrobController, I will do something like ‘return View(‘Edit’, someFrob);’. There’s no checking going on here, so I have to always manually synchronize the view and controller’s use of it. This is suboptimal, and I’m not aware of any built-in fixes.

I added this method to my controller base class:

public ActionResult ViewPage<V, M>(V view, M model)     where V : ViewPage<M>     where M : class {     return View(typeof(V).Name, model); } 

Note: The reason I take a view object that’s never used is because, AFAIK, there’s no way to get C#’s type inference to work otherwise. If I removed the view parameter, I’d need to specify V explicitly, which also means specifying M explicitly too… sigh.

So now, I can do this:

  return ViewPage(new Views.Frob.Edit(), myFrob); 

I’m specifying the exact view (no problem if it gets renamed), and myFrob is typechecked to be the right model type. The ugly side is that I new up a Edit. Alternatively, I could write:

  return ViewPage((Views.Frob.Edit)null, myFrob); 

One downside is that the the model must be an exact match. So with a ViewPage>, I cannot pass in a List. I thought this might work:

    public ActionResult ViewPage<V, M, T>(V view, T model)         where V : ViewPage<M>         where M : class          where T : M {         return View(typeof(V).Name, model);     } 

But C#’s type inference can’t figure it out. The other potential problem is that the name of the view type might not be the right name, as I think it can be overridden by attributes. But that’s an easy fix if I run into it.

Questions:

  1. How can I make this syntax cleaner?
  2. What downsides am I missing here?

Edit: With respect to the Controller knowing about the View, it only slightly does. The only thing it gets from the view is the Type, for which it grabs the name. So that’s equivalent to passing in the string name. And the strongly typed model, which must match or it’ll fail. So it doesn’t really know too much about the View — its just a trick to get the compiler to catch errors.

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

    The first problem I see is that you’ve now made your Controller aware of the View. That’s a line you should never cross.

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

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • 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 Depends on the transaction isolation level (http://en.wikipedia.org/wiki/Isolation_(database_systems)) you're using, but… May 11, 2026 at 3:15 pm
  • added an answer You probably don't need step 2 to wait since SVN… May 11, 2026 at 3:15 pm
  • added an answer You need to think of this as a tokenization issue… May 11, 2026 at 3:15 pm

Related Questions

I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
There is a conversion process that is needed when migrating Visual Studio 2005 web

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.