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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:57:50+00:00 2026-05-16T08:57:50+00:00

I don’t think this should be in my view, but instead handled by the

  • 0

I don’t think this should be in my view, but instead handled by the controller. I suppose this could be done in the SQL (can get ugly real quick) or in the controller (I think this might be best), or maybe even an HTML helper. But, I’m not sure how to unpack/repack my IQueryable/IEnumberable in the controller. I think that giving the template designer everything they need and then some is best, therefore providing both the full description as well as the excerpt (which is generated).

Thoughts/ideas appreciated.

<p>
    <% var description = Regex.Replace(Regex.Replace(spotlight.Description, "<[^>]*>", string.Empty), "[\0x0020\r\n]+", " ").TrimEnd();
        if (description.Length < 297)
        {
        %> <%= description %> <%
        } else { %>
        <%= description.Substring(0, 297) + "..." %> <%
        }                       
    %> <a href="<%= Url.Action("Details", "Spotlights", new { id=spotlight.SpotlightID}) %>">Read &raquo;</a>
</p>

My repository:

    public IQueryable<Spotlight> FindAllSpotlights()
    {
        return from spotlight in db.Spotlights
                   where spotlight.PublishDate <= DateTimeOffset.Now
                   orderby spotlight.PublishDate descending
                   select spotlight;
    }

My controller:

    public ActionResult Index()
    {
        var spotlights = spotlightRepository.FindTopSpotlights().ToList();

        return View(spotlights);
    }
  • 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-16T08:57:51+00:00Added an answer on May 16, 2026 at 8:57 am

    Suggest keeping your repository as is. Suggest that you extend your Spotlight class to encapsulate all that Regex logic in a property or method.

    Extend the behaviour of Spotlight with the nicely formatted description. That’ll keep the logic out of your View.

    public partial class Spotlight
    {
       public string WellFormattedDescription()
       {
         //all the logic to return a well formatted Spotlight.Description
        string desc = Regex.Replace(Regex.Replace(this.Description, "<[^>]*>", 
                                     string.Empty), "[\0x0020\r\n]+", " ")
                           .TrimEnd();
    
        if (desc.Length < 297)
           return desc;
        else 
           return desc.Substring(0, 297) + "...";
       }
    }
    

    Then your View simply calls:

    <p>
        <%=spotlight.WellFormattedDescription  %>
        <a href="<%= Url.Action("Details", "Spotlights", new { id=spotlight.SpotlightID}) %>">foo</a>
    </p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't need to do this right now but thinking about the future... What would
I don't understand why my output is not how I think it should be.
Don't want to sort the entries. using this does not preserve the order as
I don't know why i can't match url when url is http://localhost:8000/home/CPM%201.6.1001 since i
I don't know if thats right but for some reason my stored procedure is
I don't know if this is possible. I display a table of results and
I don't know if i am doing it right, this is what I got:
Don't be afraid to use any technical jargon or low-level explanations for things, please.
I don't know Regex very well, and I'm trying to get all of the

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.