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 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've been at this all week, trying to put the finishing touches on my
Thank you all for helping. Below this post I put the corrected version's of
I'm kind of confused. I would put all the HTML for the menu in
I put all my code in NS, similar to how jQuery is structured. I
I want to put all the requirements of a repoze Zope2 install in a
So I need to put all the names in a file into column 1
I know that I should put all the html elements in body tag, but
By someone's advice I've put all my PHP files in a separate folder (inc)
Up until now I just put all my jQuery goodness inside the $(document).ready() function,
I'm using ExpressJs with Node.js and have put all my routes into a 'routes'

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.