我正在尝试创建一些自定义地图路线,但无法使其正常工作.
我的最终目标是能够指定类似下面的内容.我基本上用URL构造了"id"和"name"的值对.这个名字是无关紧要的,仅供用户恳求,我会在我的控制器中要求ID.
/仪表板/ 5-MY-村名/ 89-MY-群名/ 133-也许偶数另一个子群
对于初学者,我正在研究第一部分并遇到麻烦.
使用以下路由浏览"http:// localhost:53933/dashboards/109-building-xyz"会生成错误 A public action method '109-building-xyz' was not found on controller 'MyInterfaceInterface.Controllers.DashboardsController'.
routes.MapRoute(
"Dashboard",
"dashboards/{id}-{name}", // URL pattern
new { controller = "Dashboards", action = "Index" },
new { id = @"\d+", name = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
显然我希望通过参数将其路由到Index函数.
我究竟做错了什么?我甚至正确地构建了这个吗?我来自web-PHP背景并使用htaccess来实现这些功能.
谢谢
我正在为我的MVC 4控制器提供友好的名称,我想做一些类似于[ActionName="My-Friendly-Name"]样式的东西,但对于整个控制器.
我找不到关于这种属性的任何信息,那么我该如何去做呢?另外,我需要添加一个新的MapRoute来处理它吗?
编辑:
例如,我想路由以下网址:
http://mysite.com/my-reports/Details/5
Run Code Online (Sandbox Code Playgroud)
被路由到以下控制器:
[ControllerClass="my-reports"] // This attribute is made up. I'd like to know how to make this functionality
public class ReportsController : Controller
{
//
// GET: /Reports/
public ActionResult Index()
{
return View();
}
public ViewResult Details(int id)
{
Report report = db.Reports.Single(g => g.Id == id);
return View(report);
}
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(Report item)
{
try
{
if (ModelState.IsValid)
{
item.Id = Guid.NewGuid();
_context.Reports.AddObject(item); …Run Code Online (Sandbox Code Playgroud) 有人可以告诉我如何使用MapRoute方法吗?我已经尝试创建自己的路线,但它不起作用.我想要实现的是将"http://servername/home/default.aspx"路由到控制器"Home"和操作"Default"的路由.此外,是否可以说如果用户正在浏览default.aspx"文件",它实际上会指向"索引"操作?
我曾尝试阅读MSDN参考和谷歌搜索,但它并没有让我更明智.
我正在使用传统的swf文件,该文件在控制器/操作路由中查找静态路由.例如,它正在尝试下载该文件
http://localhost:59801/Resource/Details/ClearExternalPlaySeekMute.swf
Run Code Online (Sandbox Code Playgroud)
当文件存在于根目录中时:
http://localhost:59801/ClearExternalPlaySeekMute.swf
Run Code Online (Sandbox Code Playgroud)
我可以用MapRoute这个URL映射到根目录吗?
我如何创建一个接受斜杠而不考虑新参数的MapRoute?如果网址是
http://localhost/root/p1/default.aspx
Run Code Online (Sandbox Code Playgroud)
我想要一个参数来获取localhost(root/p1/default.aspx)之后的所有内容.通常它需要三个参数,因为有两个斜杠,maproute用斜杠分隔参数.所以,如果路线看起来像
routes.MapRoute(
"URLMapRoute",
"{path}",
new { controller = "Home", action = "Index", path = "default.aspx" }
);
Run Code Online (Sandbox Code Playgroud)
然后{path}获取所有内容,即使url包含斜杠.
我想在地图上显示地图和绘制路线.我的应用程序支持ios 4 plus.那么我应该如何使用地图来处理ios 6以及之前的工作.另外我想知道sholud我在我的应用程序中使用自定义mapview来显示地图和路线,或者我应该使用
[[UIApplication sharedApplication] openURL:]
Run Code Online (Sandbox Code Playgroud)
我从来没有用过MapKits.所以请提供任何教程.如果有任何可以使用的rd方库,请告诉我.
我正在开发mv4网站,
当我把它们写入RouteConfig时,你能告诉我为什么这些命令在我的应用程序中没有做任何事情:
routes.LowercaseUrls = true;
routes.AppendTrailingSlash = true;
Run Code Online (Sandbox Code Playgroud) 我在RouteConfig中有3条路由:
routes.MapRoute(
name: "ByGroupName",
url: "catalog/{categoryname}/{groupname}",
defaults: new { controller = "Catalog", action = "Catalog" }
);
routes.MapRoute(
name: "ByCatName",
url: "catalog/{categoryname}",
defaults: new { controller = "Catalog", action = "Catalog" }
);
routes.MapRoute(
name: "ByBrandId",
url: "catalog/brand/{brandId}",
defaults: new { controller = "Catalog", action = "Catalog" }
);
Run Code Online (Sandbox Code Playgroud)
这是我的动作控制器接收参数:
public ActionResult Catalog(
string categoryName = null,
string groupName = null,
int pageNumber = 1,
int orderBy = 5,
int pageSize = 20,
int brandId = 0,
bool bundle = …Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc asp.net-mvc-routing maproute asp.net-mvc-5
路线
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Contact",
url: "Contact",
defaults: new { controller = "Home", action = "Contact" }
);
Run Code Online (Sandbox Code Playgroud)
我的控制器
public class HomeController : BaseController
{
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
我的Global.asax
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
}
Run Code Online (Sandbox Code Playgroud)
最后我的请求网址
http://localhost:1234/Contact/
Run Code Online (Sandbox Code Playgroud)
浏览器出错
无法找到该资源.
说明:HTTP 404.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用.请查看以下网址,确保拼写正确.
请求的网址:/联系人/
版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.18033
我究竟做错了什么? …
我想在MVC中制作几个相同的地图路线.
localhost:1010/abcd/home/index
localhost:1010/home/index/abcd
id = abcd controller = home action = index
我使用波纹管代码,但它不起作用
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"ShoppingManagment",
"{id}/{controller}/{action}",
new { controller = "ShoppingManagment",
action = "ShoppingManagment", id = UrlParameter.Optional });
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home",
action = "Index", id = UrlParameter.Optional }
);
}
Run Code Online (Sandbox Code Playgroud) 如果你想改变这种途径进行处理的方式可以做什么,在一个MVC项目或者你有改变的MVC框架?
例如,假设您在Global.asax.cs的RegisterRoutes中有标准代码:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
Run Code Online (Sandbox Code Playgroud)
但是,让我们说你真正想要发生的是让你的自定义类拦截所有传入的请求并以特殊方式路由它们.可以通过从MVC框架类继承然后自定义来完成,或者您是否必须实际更改框架代码?