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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:23:10+00:00 2026-05-23T10:23:10+00:00

I know that what I’m trying to do is bad idea, but I have

  • 0

I know that what I’m trying to do is bad idea, but I have specific constrains for now.

I have multiple sites, using one and the same MVC3 code base. For one of them the requirement is to hide some required fields from the form.

I know that the best approach is to modify the controller to set the defaults for these fields, but I’d like to achieve this modifying only the view for this particular site w/o changing the code.

So, how do I set a particular model property to a default value in the view? The ideal should be something like:

@Html.HiddenFor(model => model.RequiredProperty)
@model.RequiredProperty = "default"

EDIT: more explanation

So, actually this is in a sub-view, which is used by 2 different main views. I need these properties set only if one particular main view is used, and not the others.

So, I guess the setting to default need to go to that particular “main” view. Looks like I can not use HiddenFor in the sub-view, and then Html.Hidden in the main.

Is there a way to check in the sub-view which is the outer view?

  • 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-23T10:23:11+00:00Added an answer on May 23, 2026 at 10:23 am

    There is a Hidden helper alongside HiddenFor which lets you set the value.

    @Html.Hidden("RequiredProperty", "default")
    

    EDIT Based on the edit you’ve made to the question, you could do this, but I believe you’re moving into territory where it will be cheaper and more effective, in the long run, to fight for making the code change. As has been said, even by yourself, the controller or view model should be setting the default.

    This code:

    <ul>
    @{
            var stacks = new System.Diagnostics.StackTrace().GetFrames();
            foreach (var frame in stacks)
            {
                <li>@frame.GetMethod().Name - @frame.GetMethod().DeclaringType</li>
            }
    }
    </ul>
    

    Will give output like this:

    Execute - ASP._Page_Views_ViewDirectoryX__SubView_cshtml
    ExecutePageHierarchy - System.Web.WebPages.WebPageBase
    ExecutePageHierarchy - System.Web.Mvc.WebViewPage
    ExecutePageHierarchy - System.Web.WebPages.WebPageBase
    RenderView - System.Web.Mvc.RazorView
    Render - System.Web.Mvc.BuildManagerCompiledView
    RenderPartialInternal - System.Web.Mvc.HtmlHelper
    RenderPartial - System.Web.Mvc.Html.RenderPartialExtensions
    Execute - ASP._Page_Views_ViewDirectoryY__MainView_cshtml
    

    So assuming the MVC framework will always go through the same stack, you can grab var frame = stacks[8]; and use the declaring type to determine who your parent view is, and then use that determination to set (or not) the default value. You could also walk the stack instead of directly grabbing [8] which would be safer but even less efficient.

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

Sidebar

Related Questions

I know that Java have its own garbage collection, but sometimes I want to
I know that this question might have been asked like 100 times, but, believe
We know that IPhone has a push notification function. But I have different kinds
we know that we have to previously declare a variable using __block if we
I know that we can set it through manifest file using android:icon attribute.But how
I know that the AVD Manager can run multiple emulators but with the new
I know that Phonegap has an event for back button, but it's only available
I know that this sort of question has been asked here before, but still
I know that immutable objects always have the same state, the state in which
I know that in order to download a cookie associated with an account using

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.