+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Using Sitefinity 8.0 Classic MVC routes not working

Using Sitefinity 8.0 Classic MVC routes not working

4 posts, 0 answered
  1. Uttam
    Uttam avatar
    21 posts
    Registered:
    17 Mar 2015
    22 Apr 2015
    Link to this post

    Hi,

    I'm working with Sitefinity 8.0 to create some pages with MVC classic mode and data driven by sitefinity apis but the routes are not working and always throwing 404 "http://sitedomain/version/index or http://sitedomain/version/". I did follow the following articles but no help:

    http://docs.sitefinity.com/for-developers-classic-mvc-mode

    http://www.sitefinity.com/developer-network/knowledge-base/mvc-routing-fails-for-mvc-widgets-in-sitefinity-6.1

    Here is my routing code in global.asax:

    void Application_Start(object sender, EventArgs e)
        {
            Bootstrapper.MVC.MapRoute(
                     "Classic",
                     "thfpoc/{controller}/{action}/{id}",
                     new { controller = "Version", action = "Index", id = (string)null }
                 );              

        }

    Here is my Controller code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;

    using Telerik.Sitefinity.DynamicModules;
    using Telerik.Sitefinity.DynamicModules.Model;
    using Telerik.Sitefinity.Utilities.TypeConverters;

    namespace THF_SFPOC.Mvc.Controllers
    {
        public class VersionController : Controller
        {
            private readonly Type versionType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Version.Version");

            #region Managers

            private DynamicModuleManager dynamicModuleManager;
            public DynamicModuleManager DynamicModuleManager
            {
                get
                {
                    if(dynamicModuleManager == null)
                    {
                        dynamicModuleManager = DynamicModuleManager.GetManager();
                    }
                    return dynamicModuleManager;
                }
            }

            #endregion

            public ActionResult Index()
            {
                var contentList = GetCollectionOfVersionContent();
                return View(contentList);
            }

            public ActionResult List()
            {
                var contentList = GetCollectionOfVersionContent();
                return View(contentList);
            }
           
            private IQueryable<DynamicContent> GetCollectionOfVersionContent()
            {
                var contentCollection = DynamicModuleManager.GetDataItems(versionType);
                return contentCollection;
            }

        }
    }​

     Here is my sample View code:

    @{
        Layout = null;
        ViewBag.Title = "Index";
    }

    @using Telerik.Sitefinity.DynamicModules.Model
    @using Telerik.Sitefinity.Model

    @model IQueryable<DynamicContent>

    <!DOCTYPE html>

    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>MVC!!!</title>
    </head>
    <body>
        <div>
            <ul>
                <li><a href="/version/index/">Index</a></li>
                <li><a href="/version/list/">Full List</a></li>
            </ul><br/>
            <p>Here is the index page with full Version content list:</p>
              <ul>
                  @foreach (var version in @Model)
                  {
                    <li>@Html.Raw(version.GetString("Title"))</li>
                  }
              </ul>
        </div>
    </body>
    </html>

    Thanks!!!​

     

     

     

     ​

     ​

     

  2. Ivan Eftimov
    Ivan Eftimov avatar
    23 posts
    Registered:
    20 Jul 2016
    27 Apr 2015
    Link to this post
    Hello Uttam,

    I see that when you return the view in your action methods, you pass only the model. In that case the MVC routing is looking for a view with the action name. For example, your Index action will look for Index.cshtml view in the Views folder. 
    You have two options: 
    1. To rename your view to Index.cshtml
    2. (I recommend this) To pass the view name when you are returning the view. For example, in your index action you can return: View("Default", contentList). Please notice that in this case I assume that your view name is Default.cshtml.

    I hope that my suggestion will solve your issue. Feel free to contact us again if the issue does not get solved.


    Regards,
    Ivan Eftimov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Uttam
    Uttam avatar
    21 posts
    Registered:
    17 Mar 2015
    27 Apr 2015 in reply to Ivan Eftimov
    Link to this post

    Hi Ivan,

    Thanks for taking some time and looking into my question.

    My view is already called "Index.cshtml" and I also tried you second approach by passing the View name in the action controller as shown below but no help.

    public ActionResult Index()
            {
                var contentList = GetCollectionOfVersionContent();
                return View("Index", contentList);
            }

    I strongly feel it's a problem with routes and my entries in global.asax is ignored or a hack is required. If you have a working sample with classic MVC, can you provide me the code and I will follow the same procedure ?

    Thanks,

    Uttam

     ​

     

  4. Ivan Eftimov
    Ivan Eftimov avatar
    23 posts
    Registered:
    20 Jul 2016
    30 Apr 2015
    Link to this post
    Hello Uttam,

    After reexamining your code and what you wrote in the first ticket, I see that the route that you registered has a prefix (which is great!), but when you try to call your action in classic mode (outside a sitefinity page), you don't add that prefix to the URL. I think if you leave your code in the initial state and just browse http://sitedomain/thfpoc/version, you should be able to execute the Index action and get the appropriate view. If you want to access an action different than Index, the URL should look like this:
    http://sitedomain/thfpoc/version/{action name}

    Tell me if this works. 

    Regards,
    Ivan Eftimov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
4 posts, 0 answered