Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ross Ekberg 124 posts 365 karma points
    Sep 22, 2021 @ 17:40
    Ross Ekberg
    0

    Can't Get Partial View Macro To Work

    I am attempting to get a partial view macro to work. But it doesn't.

    My Model is EF6 so I don't know exactly how to paste it in here, but here is the specific table I am referencing. The context name is "WebSubscriptionsEntities":

        namespace Bridge.Models
        {
            using System;
            using System.Collections.Generic;
    
            public partial class SubscriptionItem
            {
                public int SubItemID { get; set; }
                public string title { get; set; }
                public Nullable<System.DateTime> post_date { get; set; }
                public string filename { get; set; }
                public Nullable<bool> active { get; set; }
                public string SubID { get; set; }
                public string posted_by { get; set; }
                public string pr_category_type { get; set; }
                public Nullable<System.DateTime> last_modified_date { get; set; }
                public string Last_modified_by { get; set; }
                public Nullable<int> PressReleaseID { get; set; }
            }
    
    }
    

    My Controller (WebSubscriptionsItemListController.cs):

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Bridge.Models;
    
    namespace Bridge.Controllers
    {
        public class WebSubscriptionsItemListController : Controller
        {
            // GET: WebSubscriptionsItemList
            public ActionResult GetSubscriptionItems()
            {
                List<SubscriptionItem> subItems = GetItems();
    
                return PartialView("WebSubscriptionItemList", subItems);
            }
    
            public List<SubscriptionItem> GetItems()
            {
                using (WebSubscriptionsEntities dc = new WebSubscriptionsEntities())
                {
                    List<SubscriptionItem> itms = dc.SubscriptionItems.Where(x => x.SubID == "31").OrderByDescending(x => x.post_date).ToList();
    
                    return itms;
                }
            }
        }
    }
    

    My Partial View (WebSubscriptionsItemList.cshtml):

    @model List<Bridge.Models.SubscriptionItem>
    
        <link rel="stylesheet" type="text/css" href="/lib/DataTables/datatables.min.css" />
    
        <div>
    
            <table id="PRs" class="table table-striped table-bordered table-hover w-100">
                <thead>
                    <tr>
                        <th scope="col">Date</th>
                        <th scope="col">Title</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var itm in Model)
                    {
                    <tr>
                        <td>@itm.post_date</td>
                        <td>@itm.title</td>
                    </tr>
                    }
                </tbody>
            </table>
    
        </div>
    
        <script type="text/javascript" src="/lib/DataTables/datatables.min.js"></script>
        <script>
        $(document).ready(function () {
            $('#PRs').DataTable();
        });
        </script>
    

    My Partial View Macro (WebSubscriptionsItemList.cshtml):

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using Bridge.Models;
    
    @Html.Action("GetSubscriptionItems", "WebSubscriptionsItemList")
    

    The error I get is:

    System.InvalidOperationException: No route in the route table matches the supplied values.

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Sep 22, 2021 @ 22:24
    Marc Goodson
    0

    Hi Ross

    I'm wondering if your routing issue is down to your Controller not being auto routed?

    If you updated it to inherit from the special base Umbraco SurfaceController

    public class WebSubscriptionsItemListController : SurfaceController

    Whether that would resolve this particular issue

    Regards

    Marc

  • Ross Ekberg 124 posts 365 karma points
    Sep 23, 2021 @ 13:29
    Ross Ekberg
    0

    Originally, I tried this and nothing changed. However, I didn't realize that I needed to 'build'the project. Once I did that, I got a different error:

    Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.
    
  • Ross Ekberg 124 posts 365 karma points
    Sep 24, 2021 @ 13:12
    Ross Ekberg
    100

    Ugh, I figured it out. There is a fricking typo in my controller.

     return PartialView("WebSubscriptionItemList", subItems);
    

    is supposed to be:

     return PartialView("WebSubscriptionsItemList", subItems);
    
  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Sep 24, 2021 @ 20:36
    Marc Goodson
    0

    Hi Ross

    How very annoying, glad you got it working though!

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft