问题描述
我只是在我的项目安装T4MVC,我碰到一些问题。
在我的控制,我可以呼叫重定向到动作没有问题:
返回RedirectToAction(Actions.Index());
如果我这样做,从我的观点调用它,我得到发生ArgumentOutOfRangeException。
@ Html.ActionLink(删除晚宴,MVC.Home.Index())
要确保我正确地做到了,我创建了一个新的MVC解决方案,该行工作。
我从我的HomeController我'baseController继承取出resintalled T4MVC,以确保它不会干涉。
我已经没有更多的想法,甚至开始寻找这一点,调试并不能帮助我,因为它似乎在延伸方法explose:
[ArgumentOutOfRangeException:索引超出范围。必须是非负并小于集合的大小。
参数名称:索引]
System.ThrowHelper.ThrowArgumentOutOfRangeException()+72
System.Collections.ObjectModel.Collection`1.set_Item(的Int32指数,T值)10419142
System.Web.Mvc.ControllerContext.get_RequestContext()+25
System.Web.Mvc.Html.LinkExtensions.RouteLink(的HtmlHelper的HtmlHelper,LINKTEXT字符串,字符串routeName,字符串协议,主机名字符串,字符串片段,RouteValueDictionary routeValues,IDictionary`2 htmlAttributes)+47
System.Web.Mvc.T4Extensions.ActionLink(的HtmlHelper的HtmlHelper,字符串LINKTEXT,结果的ActionResult,IDictionary`2 htmlAttributes,字符串协议,主机名字符串,字符串片段)+196
System.Web.Mvc.T4Extensions.ActionLink(的HtmlHelper的HtmlHelper,字符串LINKTEXT,ActionResult的结果)+72
ASP._Page_Views_Home_Index_cshtml.Execute()在C:\\ Thva \\杂项\\ DropBox的\\工作\\ MyProjects下\\ Wims的\\ Wims.Website \\查看\\首页\\ Index.cshtml:53
你知道吗?
在此先感谢
修改:我只是尝试这样做,它仍然无法正常工作:
创建一个新的控制器:
使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.Mvc;命名空间Wims.Website.Controllers
{
公共部分类MyTestController:控制器
{
//
// GET:/ MyTest的/ 公共虚拟的ActionResult指数()
{
返回查看();
} }
}
运行AutoT4MVC,
查看:
@ {
ViewBag.Title =指数;
}
@ Html.ActionLink(aiaieiae,MVC.MyTest.Index())
< H2>指数< / H>
要确保我没有depedency,它仍然当我把我的网页不工作:
的http://本地主机:2303 / MyTest的/指数
我看着这个与大卫Ebbo(非常感谢他为他的时间),并不能找到为什么它不工作。
在我的项目中复制粘贴T4MVC code用我自己的名字空间,并使用这些它的工作方法。
所以,我只是一个重建新的MVC网站和重新导入的一切..不好玩,但我相信T4MVC一点,实在值得麻烦:)
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
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 :)
这篇关于T4MVC ArgumentOutOfRangeException在视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!