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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:57:45+00:00 2026-05-28T00:57:45+00:00

I have a partial view that sometimes needs to collect data and sometimes just

  • 0

I have a partial view that sometimes needs to collect data and sometimes just needs to display the saved data and not allow editing.

I would like to use the same partial view for both needs because the formatting is complex. However, I don’t want to just apply the “disabled” tag to specific controls: I want (on the server side) to render the read-only data as text, not as controls, so that it can’t be posted back.

(To complicate things, there is one field, for comments, that can be edited even when all the other fields are read-only, so there will be a post back.)

I’m thinking about a general solution to this problem. The simplest thing to do would be to apply the following code pattern to all the fields:

@{ if(condition) {
   @Html.TextBoxFor(model=>model.Field)
}
else 
{
   @Html.DisplayFor(model=>model.Field)
}
}

But that’s inelegant and can lead to harder to read code. Also, since the pattern has to be manually applied, it would be easy to make mistakes.

I was toying with writing some extension methods to supplement TextBoxFor, et al, that would take an additional parameter that indicated whether to invoke TextBoxFor or DisplayFor.

But what I’d like even better would be something that I could set on a containing element that would automatically affect how the child elements are rendered, the way you can set the Visible property on an ASP.NET WebForms Panel control.

So now I’m treading out into the field of the hypothetical. To achieve such a thing, I would need a server-side containing element (perhaps following the same pattern as BeginForm) that had awareness of its own scope and could affect how the rendering extension calls it contained were invoked.

Is such a thing even possible?

  • 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-28T00:57:46+00:00Added an answer on May 28, 2026 at 12:57 am

    I would look at this post: http://kazimanzurrashid.com/posts/asp-dot-net-mvc-viewmodel-usage-and-pick-your-best-pattern

    It has an approach that remove logic, procedural code from Views and promotes better OOP and encapsulation. You may find it useful, at least informative.

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

Sidebar

Related Questions

I have a partial view that I use for editing and creating my models.
I have a partial view that needs to get loaded between two div but
I have a partial view that when the user clicks a button, some data
I have a simple Partial View that I would like to automatically call a
I have a partial view that is not rendering: The designer is telling me
I have a partial view that I want to basically take care of itself
I have a partial view that is shared between two controllers and I'm trying
I have a partial view (UserControl) that implements a simple pager in my Asp.Net
I have an ASP.NET MVC Partial View that contains a Html.TextBox that is configured
I'm using MVC2 with VS2010 I have a view that has two partial views

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.