Copied to clipboard

Flag this post as spam?

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


  • aaron1986 2 posts 22 karma points
    Aug 31, 2023 @ 17:59
    aaron1986
    0

    No route in the route table matches the supplied values

    I have three files one is called 'TwitterController.cs', the second one is called 'Latest Tweets.cshtml' and the third is called 'Home.cshtml'. When I load the page, I get the Error 'No route in the route table matches the supplied values'. Moreover, if I build the program in Visual Studio - it reports 'no errors', but the program still cannot load.

    I know this is a very common problem, but I cannot find a solution to help me solve this issue.


    TwitterController.cs

    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Web.Mvc;
    using Umbraco.Web.Mvc;
    namespace HighlyDeveloped.Core.Controllers
    {
    public class TwitterController : SurfaceController
    {
        public ActionResult GetTweets(string twitterHandle)
        {
            string PARTIAL_VIEW_FOLDER = "~/Views/Partials/";
            return PartialView(PARTIAL_VIEW_FOLDER + "Latest Tweets.cshtml", twitterHandle);
           }
    
       }
    }
    

    Latest Tweets.cshtml

        @Model string
       <h1>Load the tweets for @Model</h1>
    

    Home.cshtml

    <!-- Latest Tweets -->
    <div class="container">
       <div class="row">
           <div class="col">
    @Html.Action("GetTweets", "Twitter", new { twitterHandle = "twitter@676767" })
    @Umbraco.RenderMacro("GetLatestTweets", new {twitterHandle="twitter@676767})
        </div>
    </div>
    

  • Luuk Peters 85 posts 330 karma points
    Sep 01, 2023 @ 10:02
    Luuk Peters
    0

    Could you try Html.RenderAction instead of Action? And you may want to mark the GetTweets function with the [ChildActionOnly] attribute.

  • aaron1986 2 posts 22 karma points
    Sep 01, 2023 @ 11:50
    aaron1986
    0

    I have amended my code (please see below), but I am still getting the same Error. I have added [ChildActionOnly] to the TwitterController.cs file, and updated the Home.cshtml file.

    TwitterController.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Web.Mvc;
    using Umbraco.Web.Mvc;
    
    namespace HighlyDeveloped.Core.Controllers
    {
    public class TwitterController : SurfaceController
    {
        [ChildActionOnly]
        public ActionResult GetTweets(string twitterHandle)
        {
    
            string PARTIAL_VIEW_FOLDER = "~/Views/Partials/";
            return PartialView(PARTIAL_VIEW_FOLDER + "Latest Tweets.cshtml", twitterHandle);
           }
    
        }
    }
    

    Home.cshtml

    <!-- Latest Tweets -->
    <div class="container">
    <div class="row">
        <div class="col">
    
            @{Html.RenderAction("GetTweets", "Twitter", new { twitterHandle = "twitter@676767" });}
    
            @Umbraco.RenderMacro("GetLatestTweets", new { twitterHandle = "twitter@676767" })
        </div>
    </div>
    

Please Sign in or register to post replies

Write your reply to:

Draft