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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:38:24+00:00 2026-05-16T03:38:24+00:00

I need advice on what I need to do to make the following two

  • 0

I need advice on what I need to do to make the following two blocks of code reusable. I have to produce another table of funds and while I’m doing that, I’d like to create FundsTable.ascx partial view that all Views that need to display a fund table can use.

// Inherits="System.Web.Mvc.ViewPage<CompanyViewModel> // this is a company
<%foreach (var fund in Model.PageFunds){%>

    <% foreach (var shareClass in fund.ShareClasses) {%>

        <tr class="shareclass">
            <td>
                // displays an image if the ViewModel's Company is not unlisted
                <%= Html.TearsheetImage((Model.Company.ListingType != ListingType.UNLISTED))%>
            </td>
        </tr>
<% } }%>

and

// Inherits="System.Web.Mvc.ViewPage<GroupViewModel> // this is a group of companies
<%foreach (var fund in Model.PageFunds){%>

    <% foreach (var shareClass in fund.ShareClasses) {%>

        <tr class="shareclass">
            <td>
                // displays an image if any Company in the ViewModel's 
                // List<Company> is not unlisted
                <%= Html.TearsheetImage(
                        (Model.Companies.WithCompanyId(fund.Company.Id) != ListingType.UNLISTED))%>
            </td>
        </tr>
<% } }%>

I think I need to abstract the differences away somewhere, but I’m not sure where to put it. Is there any rule-of-thumb I should be following here?

Should both CompanyViewModel & GroupViewModel implement an interface that decides whether the item is Unlisted? Also, what type should my FundTable.ascx be? I was thinking both CompanyViewModel & GroupViewModel could extend FundViewModel (or something) and I could make FundTable a ViewUserControl<FundViewModel> but I don’t think that’ll work because the functionality needed to determine whether to display the image needs to come from CompanyViewModel & GroupViewModel independently.

Plus, the more I think about this the more I’m cunfusing my self! Any ideas or suggestions? Thankss

  • 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-16T03:38:24+00:00Added an answer on May 16, 2026 at 3:38 am

    If I’m reading this right the code only differs in how you determine whether to display the image.

    If this is right this is the perfect place to do a little functional programming!

    Create a view model for your .ascx. we’ll call it FundsTable.

    It will have two properties:

    Func<PageFund,bool> ShowImage {get;set;}
    IEnumerable PageFund Funds {get;set;}
    

    Make your FundsTable.ascx strongly typed to this object.

    Now your logic on whether to display can be passed in:

    FundsTable ft = new FundsTable();
    ft.ShowImage = f => f.SomeCombinationOfLogic == SomeOtherThing; //<-- Your function can be anything that returns a bool
    

    Now you can do:

    <% foreach (var shareClass in fund.ShareClasses) {%>
    
        <tr class="shareclass">
            <td>
                // displays an image if any Company in the ViewModel's 
                // List<Company> is not unlisted
               <% if(Model.ShowImage(fund)) {%>
                   <%= Html.TearsheetImage(fund)%>
               <% } %>
            </td>
        </tr>
    

    Now, its kind of hard for me to tell how the classes relate to each other so you might have to shift the types and logic, but an approach like this should work. Whne you setup your view model for the table simply pass in the function that will determine whether to show the image. Add another Func property if that Tearsheet lookup needs that complexity.

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

Sidebar

Related Questions

I'd need advice on following situation with Oracle/PostgreSQL: I have a db table with
I really need advice on how to do the following. I have tried several
I have the following issue and need a patter to solve it: To make
I have the following regular expression, and i need some advice about it. I
I need advice on the following HTML: <!-- Beginning of ROW !--> <div id="row1">
I need advice on how to change the file formatted following way file1: A
I think I have this working but I need advice. I'd like to know
I have 3 tables, I need advice on how to get data from them.
By having into consideration the following scheme: We need to make sure that, if
I have the following: I would like to make it so that the tableview

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.