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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:39:38+00:00 2026-05-20T07:39:38+00:00

In my controller I want to specify a different View than default. Like this

  • 0

In my controller I want to specify a different View than default.
Like this :

public ActionResult EditSurvey(Int32 id)
    {

        Survey survey = _entities.Surveys.Single(s => s.Id == id);

        return View("Survey",survey);
    }

But instead of specifying the view as a string (“Survey”) I would like to reference it directly, so if I decide to change the name of my view later on I don’t have to change this string manually.

So I’m looking for something like this :

public ActionResult EditSurvey(Int32 id)
    {

        Survey survey = _entities.Surveys.Single(s => s.Id == id);

        return View(Views.Admin.Survey,survey);
    }
  • 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. Editorial Team
    Editorial Team
    2026-05-20T07:39:38+00:00Added an answer on May 20, 2026 at 7:39 am

    Good question, there is no inbuilt support as the View() method expects a string, but there is a Nifty tool called T4MVC created by David Ebbo that does just that.

    The documentation on codeplex has a manual install procedure, I would recommend getting it with NuGet package manager straight from VS2010.

    Its pretty simple, the whole thing is files which you can just add to your project. (T4MVC.tt and T4MVC.settings.t4), everytime you change your code, (1) Right-click T4MVC.tt and (2) Click “Run Custom Tool”.

    What it does is generate a class with Subclasses, Members, Properties for all your Controllers and Views. What it even does is create strong types for all your content, like images, css, js etc. (Which I think is just awesome)

    Examples:
    This

    @Html.RenderPartial("DinnerForm");
    

    Would be:

    @Html.RenderPartial(MVC.Dinners.Views.DinnerForm);
    

    This:

    @Html.ActionLink("Delete Dinner", "Delete", "Dinners", new { id = Model.DinnerID }, null)
    

    Would Be this instead:

    @Html.ActionLink("Delete Dinner", MVC.Dinners.Delete(Model.DinnerID))
    

    This :

    <img src="/Content/nerd.jpg" />
    

    Would be this instead:

    <img src="@Links.Content.nerd_jpg" />
    

    You do have to Right-Click on the tt file and “Run Custom Tool” as mentioned before every time you change your views, controllers, however, if you want to automate this, Check out Chirpy which does that and more.

    (Note T4MVC has aspx/mvc2 examples on the docs but works fine on MVC3 as I use in production with a MVC3/Razor app)

    Also see T4MVC tag on SO.

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

Sidebar

Related Questions

In my Rails controller I want to branch to a different controller's action, show
I have this code in my controller and want to test this code line
I'm using a g:select (actually, a g:currencySelect) in my view. I want a controller
I want to call a controller function from a view. Is that possible in
I want to access the value of a view controller data member variables in
So I want to be able to specify multiple different sources for my FullCalendar
I wanted to have more than one controller and view for same object/model in
Like the titles says, I want to specify the super of an NSArrayController ,
I want to use the Model-View-Controller template while writing my Web App. The problem
I want my controller to return the right HTTP response code when the user

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.