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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:16:23+00:00 2026-05-18T00:16:23+00:00

So, I put all this logic in my view, thinking it would be helpful

  • 0

So, I put all this logic in my view, thinking it would be helpful to follow the DRY principle.

Basically, this replicates a paper form, and in my view model, I have pairs of properties named like XXXCondition and XXXComment which put together form an InspectionDetail in my actual model.

   <table>
    <% string secname ="";
       foreach (PropertyInfo p in typeof(InspectionFormModel).GetProperties()) {
           object[] sec = p.GetCustomAttributes(typeof(InspectionSection), false);
           object[] name = p.GetCustomAttributes(typeof(DisplayNameAttribute), false);
           string propname = p.Name;

           /* Display a row for all view model properties having InspectionSection Attribute */
           if ( sec.Length > 0) {

               /* New Subheading */
               if (((InspectionSection)sec[0]).Section.ToString() != secname) {
                   secname = ((InspectionSection)sec[0]).Section.ToString();
                   var secdesc = typeof(InspectionDetail.DetailTypes).GetMember(secname)[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
                   string ssecdesc = (secdesc.Length == 0) ? secname : ((DescriptionAttribute)secdesc[0]).Description;
                   %> <tr><th><%= ssecdesc %></th><th>Condition</th><th>Remarks</th></tr><%
               }

               /* Use DisplayName attribute for item instead of property name if specified */
               if (name.Length > 0)
               {
                   propname = ((DisplayNameAttribute)name[0]).DisplayName;
               }%>
    <tr>
        <td><label for="<%= p.Name %>"><%= propname %></label></td>
        <td><%= Html.DropDownList(p.Name, (IEnumerable<SelectListItem>)ViewData["ItemConditions"]) %></td>
        <td><%= Html.TextBox(p.Name.Replace("Condition", "Comment"), null, new {Class ="comment"}) %></td>
    </tr>
    <% } } %>
    </table>

All this code in the view seems like a definite anti-pattern. Would there be a better place to hide this? Or is it foolish to rely on the order properties are defined in a view model at all?

  • 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-18T00:16:24+00:00Added an answer on May 18, 2026 at 12:16 am

    Have you looked at things like MVC templates: http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html?

    You should probably also create a custom view model and initialize it in your controller/action method from the various attributes etc.

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

Sidebar

Related Questions

I would like to know how to put all of my ListView rows into
We put all of our unit tests in their own projects. We find that
I am trying to put all the pieces together for my MVVM Silverlight application
I've frequently encountered sites that put all of their JavaScript inside a namespace structure
In my project I have put all my css classes in the style sheets.
I have been wondering how to put all the stored procedures on a SQL
Usually when I build a site, I put all the CSS into one file,
I have information spread out across a few databases and want to put all
Digital commercial products that customers pay for download link. I have put all the
Can I put my bin folder with all of its .dll files at a

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.