我正在做一个ASP.NET MVC 3 Web服务,我一直在间歇性地得到这个例外.
堆栈跟踪:
Server Error in '/' Application.
A route named 'ListTables' is already in the route collection. Route names must be unique.
Parameter name: name
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: A route named 'ListTables' is already in the route collection. Route names must be unique.
Parameter name: name …
Run Code Online (Sandbox Code Playgroud) 关于部分观点,我有两个问题......
何时使用部分视图与@helper方法,我已经互换使用,并希望在使用中更加一致.你们做什么的?
如何从其他区域引用局部视图.
我有一个名为admin的区域,我在常规的Views目录中有一个局部视图.我如何使用它..我尝试了以下不能工作,因为它无法找到.
@Html.Partial(VirtualPathUtility.ToAbsolute("~/Views/ControllerName/_PartialView"),
Model)
Run Code Online (Sandbox Code Playgroud)
其他我试过 -
@Html.Partial("~/Views/ControllerName/_PartialView", Model)
Run Code Online (Sandbox Code Playgroud) 在单个项目解决方案中,当您拥有大量控制器时引入区域确实可以改善分离,并允许模块轻松地复制到解决方案中或从解决方案中复制出来.但是,在大型企业解决方案中,我倾向于将逻辑拆分为单独的项目.
因此具有单独的UI,Controller,SOA,Model和Repository项目.在这种情况下,区域不再有意义了,而且它们为Url添加了额外的顶层,这通常是不需要的,但我相信如果你保持控制器的独特性,你可以省略Url中的区域,但不是有点臭吗?
区域可能适用于中等复杂度的站点,或者模块代码更好地保存在一个位置,因此可以将其复制到其他站点或删除.
我一直在尝试关注此博客以使区域运作:
http://mstechkb.blogspot.com/2010/10/areas-in-aspnet-mvc-20.html
在博客文章中,它标识了为每个区域设置身份验证的能力,例如:
<location path="Area1">
<system.web>
<authentication mode="Windows" />
<authorization>
<allow roles="role1,role2"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在Visual Studio 2010中的新项目中创建它时,运行时出现以下错误:
在应用程序级别之外使用注册为allowDefinition ='MachineToApplication'的部分是错误的.此错误可能是由于未在IIS中将虚拟目录配置为应用程序引起的.
从我可以看到这是因为你不能指定一个身份验证元素,除非它在顶级web.config中.
那么博客文章可以做什么呢?您是否可以在web.config中的Location元素中包含具有Authentication元素的区域?
我在MVC 3中使用了多个区域,而且我的查看无法找到问题.路由似乎正确地拾取我的控制器(所有操作都没有任何问题地执行),但是当我返回视图MVC时根本找不到它.
因此,如果我在一个名为'Some'的区域中有一个名为'Thing'的简单控制器,我会执行以下操作...
public ActionResult Index()
{
return View("Index");
}
Run Code Online (Sandbox Code Playgroud)
操作正确执行,但MVC找不到视图,我会收到类似的消息
未找到视图'索引'或它的主人......它将显示所有搜索到的位置,这将是
〜/ Views/Thing/Index.cshtml~/Views/Shared/Index.cshtml
等等,但它没有看
〜/一些/浏览/事/ Index.cshtml
关于我做错了什么的任何想法?
当.net mvc 4中的验证失败时,我有一个任务为文本框设置红色边框.
BExtensionMethods.cs
public static string GetTextBoxColor(this ModelStateDictionary ModelState)
{
string textBoxColor = string.Empty;
int count = 1;
var errorKeys = (from item in ModelState
where item.Value.Errors.Any()
select item.Key).ToList();
foreach (var item in errorKeys)
{
textBoxColor += string.Format("{0}.{1}</br>", count, item);
count++;
}
return textBoxColor;
}
Run Code Online (Sandbox Code Playgroud)
这里json对象包含值.如何过滤它?
我有一个MVC3应用程序,有几个区域和一个便携式区域(使用MVCContrib)
通常,我将所有内容文件保存在〜/ Content和我的脚本下〜/ Scripts.
但是,我正在为我的网站上的另一个服务构建一个相当复杂的webclient,我想在Area的文件夹结构下组织这些javascript和图像文件(很多图像文件和资源),看起来像这样,在〜/ Areas/Web客户端
我有一个资源聚合器控制器(我的一个可移植区域),能够很好地进入CSS/JS文件夹以提供该内容.但是,CSS文件直接引用images/fonts文件夹,所有这些链接都显示为已损坏.我有两次和三次检查路径,并确保一切正常,但我仍然得到404错误.
据我所知,MVC3应该忽略路由,只要那里有静态文件.此外,据我所知,只有App_*文件夹享有特殊保护.我错过了什么?如果我可以完全避免它,我宁愿不将我的图像和资源与我的主应用程序混合在一起.
举个例子:http://localhost/Areas/WebClient/Content/images/knownimage.png不起作用,但应该存在!
我试图将我的模型List <Models.Statement> statementList从一个动作传递到另一个动作但我在第二个控制器中接收空值.请在这里建议有什么问题.甚至试过:
return RedirectToAction("WriteInTemplate", new { statementList = statementList });
Run Code Online (Sandbox Code Playgroud)
请帮忙.
public ActionResult SendPdfStatement(string InvoiceNumber)
{
try
{
InvoiceNumber = InvoiceNumber.Trim();
ObjectParameter[] parameters = new ObjectParameter[1];
parameters[0] = new ObjectParameter("InvoiceNumber", InvoiceNumber);
List<Models.Statement> statementList = new List<Models.Statement>();
statementList = _db.ExecuteFunction<Models.Statement>("uspInvoiceStatement", parameters).ToList<Models.Statement>();
//WriteInTemplate(statementList);
return RedirectToAction("WriteInTemplate", statementList );
}
catch (Exception e)
{
InvoiceSearchTool.Models.udtExceptionTable exception = new udtExceptionTable();
exception.MethodName = "SendPdfStatement";
exception.Exception = e.ToString();
exception.Date = DateTime.Now;
DYNAMICS_EXTEntities db = new DYNAMICS_EXTEntities();
db.AddToudtExceptionTables(exception);
db.SaveChanges();
return View("Error");
}
}
public ActionResult …
Run Code Online (Sandbox Code Playgroud) c# model-view-controller asp.net-4.0 asp.net-mvc-3-areas asp.net-mvc-3
我ViewContext.RouteData.Values["Controller"]
用来获取控制器名称或ViewContext.RouteData.Values["action"]
在视图中获取操作名称(实际上在_Layout中),但是对于区域来说这ViewContext.RouteData.Values["Area"]
不起作用.您有什么建议在programmaticaly视图中获取区域名称?
我有一个测试解决方案,只有一个区域叫做Admin.
我想在许多其他Web应用程序中重用Admin.
我在IIS中的Web应用程序的设置,我已经加入虚拟应用程序,/Admin
来自哪里Areas\Admin
.
当我导航到/ Admin时,我看到了一个目录列表.当我尝试击中控制器时,/ Admin/News.我收到404错误.可能是这些区域没有注册,即使代码存在于global.asax中.但是,我确信我这一切都是错的.
请建议改变这种情况.
asp.net-mvc asp.net-mvc-routing reusability asp.net-mvc-3-areas asp.net-mvc-3