Using Sitefinity 8.0 Classic MVC routes not working
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 "sitedomain/.../index or http://sitedomain/version/". I did follow the following articles but no help:
docs.sitefinity.com/for-developers-classic-mvc-mode
www.sitefinity.com/.../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!!!
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
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
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 sitedomain/.../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:
sitedomain/.../action name
Tell me if this works.
Regards,
Ivan Eftimov
Telerik