Search code examples
razorasp.net-mvc-4t4mvc

T4MVC ArgumentOutOfRangeException in View


I just installed T4MVC on my project and I run into some problem.

In my controller i can call redirect to action without problem:

  return RedirectToAction(Actions.Index());

If i do call it from my view, i get an ArgumentOutOfRangeException.

@Html.ActionLink("Delete Dinner", MVC.Home.Index())

To make sure I did it correctly, i created a new MVC solution and that line works. I removed from my HomeController my 'baseController' inheritance and resintalled T4MVC to be sure it wouldn't interfere. I've no more idea where even start to look for this, debug doesn't help me as it seems to explose in the extention method:

[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]
   System.ThrowHelper.ThrowArgumentOutOfRangeException() +72
   System.Collections.ObjectModel.Collection`1.set_Item(Int32 index, T value) +10419142
   System.Web.Mvc.ControllerContext.get_RequestContext() +25
   System.Web.Mvc.Html.LinkExtensions.RouteLink(HtmlHelper htmlHelper, String linkText, String routeName, String protocol, String hostName, String fragment, RouteValueDictionary routeValues, IDictionary`2 htmlAttributes) +47
   System.Web.Mvc.T4Extensions.ActionLink(HtmlHelper htmlHelper, String linkText, ActionResult result, IDictionary`2 htmlAttributes, String protocol, String hostName, String fragment) +196
   System.Web.Mvc.T4Extensions.ActionLink(HtmlHelper htmlHelper, String linkText, ActionResult result) +72
   ASP._Page_Views_Home_Index_cshtml.Execute() in c:\Thva\Misc\DropBox\Work\MyProjects\Wims\Wims.Website\Views\Home\Index.cshtml:53

Any idea? Thanks in advance

Edit: I just tried this and it still doesn't work: Create a new controller:

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

namespace Wims.Website.Controllers
{
    public partial class MyTestController : Controller
    {
        //
        // GET: /MyTest/

        public virtual ActionResult Index()
        {
            return View();
        }

    }
}

Run AutoT4MVC, View :

@{
    ViewBag.Title = "Index";
}
@Html.ActionLink("aiaieiae", MVC.MyTest.Index())
<h2>Index</h2>

To make sure i have no depedency, and it still doesn't work if i call my page:

http://localhost:2303/MyTest/index

Solution

  • I've looked into this with David Ebbo (thanks a lot to him for his time), and could not find why it's not working.

    After copy pasting T4MVC code in my project with my own name space and use those methods it was working..

    So, i just recreated a new MVC Website and reimported everything.. not fun but i believe T4MVC worths the trouble :)