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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:20:13+00:00 2026-05-16T14:20:13+00:00

I have a partial view (ascx) for displaying the top x articles of a

  • 0

I have a partial view (ascx) for displaying the top x articles of a person’s RSS feed:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Models.Article>>" %>

    <% foreach (var item in Model) { %>

        <a href="<%: item.Url %>"><%: item.Title %></a><br />
        <%: String.Format("{0:g}", item.Date) %><br />
        <%: item.Body %>
        <br />

    <% } %>

In addition, I have a method that takes an RSS URL and returns an IEnumerable of type Article:

public static class ArticleFeedHelper
{
    public static IEnumerable<Models.Article> GetArticles(string feedUrl)
    {
        // Uncaught exception can happen here (e.g. 404, malformed RSS, etc.)
    }
}

On one of my views, I call the partial view like this:

<div id="articleList" class="section">
    <div class="sectionTitle">My Recent Articles</div>
    <hr />
    <div class="sectionBody">
        <% Html.RenderPartial("ArticleList", ArticleFeedHelper.GetArticles(Model.RSSFeed)); %>
    </div>
</div>

The problem is that I would like to surface an error message to the main view. Just because the RSS feed cannot be retrieved should not be so disruptive that it jettisons the user to a full error page.

RESOLUTION:

The partial view, and ArticleFeedHelper stayed the same.

Using Dave’s suggestions, the main view was changed to:

<div id="articleList" class="section">
    <div class="sectionTitle">My Recent Articles</div>
    <hr />
    <div class="sectionBody">
        <% Html.RenderAction("ArticleList", "ArticleList", new { feedUrl = Model.RSSFeed }); %>
    </div>
</div>

A partial controller was added:

public class ArticleListController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    [ChildActionOnly]
    public ActionResult ArticleList(string feedUrl)
    {
        try
        {
            IEnumerable<Models.Article> articles = Helpers.ArticleFeedHelper.GetArticles(feedUrl);
            return PartialView(articles);
        }
        catch (Exception ex)
        {
            // Handle the error and return an error partial view
        }
    }
}

And a route was added:

routes.MapRoute(
    "ArticleList", // Route name
    "{controller}/{action}/{feedUrl}", // URL with parameters
    new { controller = "ArticleList", action = "ArticleList", feedUrl = "" } // Parameter defaults
);
  • 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-16T14:20:14+00:00Added an answer on May 16, 2026 at 2:20 pm

    The cleaner way would be to use RenderAction that calls an action, which loads the feed data and can then catch errors.

    RssWidget action on ServicesController (could actually reside in every controller, doesn’t matter, but I think, that’s a clean solution):
    This action loads the articles from the feed. Note that the code is only demo and you have to replace RssService.GetArticles() by your implementation of loading the articles. If all goes right, a PartialView (named RssWidget.ascx) is returned, that shows a list of articles.

    public ServicesController : Controller
    {
        public ActionResult RssWidget()
        {
            try
            { 
                var articles = RssService.GetArticles() // or whatever the articles'
                                                        // source is
                return PartialView(articles);
            }
            catch
            {
                return PartialView("Error");
            }
        }
    }
    

    RssWidget.ascx: This is the (partial) view which is used to render the list of articles. Don’t forget to replace Article with your actual Type for the articles:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Article>>" %>
    
    <% foreach(var article in Model) { %>
        <div class="article">
            <h3><%= Html.Encode(article.Title) %></h3>
            ...
        </div>
    <% } %>
    

    The View where the RssWidget is displayed. You can render this “widget” in any view, you want to. RenderAction("RssWidget", "Services") tells the framework to execute the RssWidget action on the ServicesController and to insert the result in the actual view.

    ...
    <div id="articleList" class="section">
        <div class="sectionTitle">My Recent Articles</div>
        <hr />
        <div class="sectionBody">
            <% Html.RenderAction("RssWidget", "Services"); %>
        </div>
    </div>
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inside the Views -> Shared folder I have the DateTime.ascx partial view; <%@ Control
I have a partial view which is displayed on the top right of every
I have ascx partial view with html-layout like that <%=Html.ActionLink<PersonController>(x => x.Publications(param1, param2, ...
I have 4-5 partial view files (.ascx) like abc.ascx, cde.ascx, fgh.ascx. I want to
I have a partial view called StudentInfo.ascx. In it I have something like this:
I have a strongly typed partial view CheckBox.ascx that renders a checkbox. This is
I am editing and have already saved a Vendor.ascx partial view in VS 2010.
I am working on ASP.NET MVC3. I have a partial view RestaurantAdminNavigation.ascx which i
I Have 2 views. ProductForm.aspx and Category.ascx. CategoryForm is a Partial View. I Call
I have a partial view (Company.ascx) in the DisplayTemaplates folder. I can render its

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.