【发布时间】:2012-11-30 03:50:56
【问题描述】:
在我的 MVC 解决方案中,我有不同的区域。该区域的注册之一是类如下所示。
public class CommercialAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Commercial";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Commercial_default",
"Commercial/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
}
基于此,url hxxp://localhost:63363/Commercial/VesselManagement 应该调用 VesselManagement 控制器的 Index 操作方法。它确实偶尔会按预期调用。但是现在它不执行 action 方法。
但是,如果我将 Url 键入为 hxxp://localhost:63363/Commercial/VesselManagement/index/abc,则会调用 Action 方法 Index 并传递参数 abs。
不仅对于这个操作方法,而且对于整个应用程序中的所有操作方法,都必须以这种模式调用 url。可能是什么问题。提前感谢大家的帮助。
注意:我用的是hxxp insted of http
Global.asx
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
//RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
//Configure FV to use StructureMap
var factory = new StructureMapValidatorFactory();
//Tell MVC to use FV for validation
ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(factory));
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
}
}
VesselManagement Index() 操作
public ActionResult Index()
{
InitialData();
return View();
}
注意:刚才我注意到索引不带任何参数,但我知道这会影响路由。
【问题讨论】:
-
您能否展示您的其他路线,例如全球范围内的路线?我的猜测是一条不同的路线正在选择它,但如果没有更多上下文,我无法确定。
-
VesselManagement的签名是什么?id参数是可空类型吗? -
当
hxxp://localhost:63363/Commercial/VesselManagement被调用时找不到资源。 HTTP 404。您正在查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请检查以下 URL 并确保其拼写正确。
标签: asp.net-mvc-4 asp.net-mvc-routing