Tag: asp.net mvc routing

具有共享布局的ASP.NET MVC区域

我在ASP.NET MVC 3应用程序中定义了一个区域(Admin),在该区域创build了_ViewStart.cshtml并添加了Layout = "~/Views/Shared/_Layout.cshtml"; 要有一个统一的网站布局。 我还将以下代码添加到_Layout.cshtml : if (HttpContext.Current.User.IsInRole("Admin")) { <li>@Html.ActionLink("Items List", "Index", "Items", new { area = "Admin" }, null)</li> } Admin区域显示正确_Layout.cshtml作为其布局。 但是页面中的所有导航链接都指向Admin子文件夹。 例如,在我的布局中,我有<li>@Html.ActionLink("About Us", "About", "Home")</li> ,它指向Mysite/Home/About 。 但点击pipe理链接后,“关于我们”链接指向/Admin/Home/About 。 我应该怎么做_Layout.cshtml链接指向正确的地址? 谢谢。

我如何创build一个System.Guidtypes的路由约束?

任何人都可以在正确的方向上指出我如何绘制需要两个GUID的路线? 即。 http://blah.com/somecontroller/someaction/ {firstGuid} / {secondGuid} firstGuid和secondGuid都不是可选的,并且必须是system.Guidtypes?

属性路由不在区域工作

场景:我在ASP.NET MVC 5站点中有一个Forms区域。 我正尝试redirect到使用新的“属性路由”function定义的自定义路由的“详细信息操作”。 RedirectToAction: return RedirectToAction("Details", new { slug }); 我正在redirect到的操作: [HttpGet] [Route("forms/{slug}")] public ActionResult Details(string slug) { var form = FormRepository.Get(slug); … return View(model); } 我希望redirect到http://localhost/forms/my-slug ,而是应用程序将我redirect到http://localhost/Forms/Details?slug=my-slug 。 这意味着属性路由不起作用。 这怎么解决? 我已经添加了routes.MapMvcAttributeRoutes(); 行到我的RouteConfig: public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapMvcAttributeRoutes(); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller […]

ASP.NET MVC – 提取URL的参数

我试图提取我的url的参数,就像这样。 /行政/客户/编辑/ 1 摘录: 1 /pipe理/产品/编辑/ 18?允许=真 摘录: 18?allowed = true /pipe理/产品/创build?允许=真 摘录: ?allowed = true 有人可以帮忙吗? 谢谢!

如何从儿童行动中获得当前的控制者和行动?

我有一部分视图是通过RenderAction调用一个子操作呈现的。 如何从这个子操作中获得父控制器和操作。 当我使用.. @ViewContext.RouteData.Values["action"] 我找回儿童行动的名称,但我需要的是家长/电话行动。 谢谢 顺便说一句我正在使用MVC 3与剃刀。

ASP.NET MVC – 如何获得一个行动的完整path

在视图的内部,我可以得到一个完整的路线信息的行动? 如果我在控制器MyController中有一个名为DoThis的动作。 我可以到"/MyController/DoThis/"的path吗?

没有find'索引'或其主人的观点。

The view 'Index' or its master was not found. The following locations were searched: ~/Views/ControllerName/Index.aspx ~/Views/ControllerName/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx 使用ASP.Net mvc区域时出现此错误。 区域控制器操作被调用,但它似乎在“基础”项目视图中而不是在区域视图文件夹中寻找视图。

MVC 3不能传递string作为视图的模型?

我有一个奇怪的问题,我的模型传递给视图 调节器 [Authorize] public ActionResult Sth() { return View("~/Views/Sth/Sth.cshtml", "abc"); } 视图 @model string @{ ViewBag.Title = "lorem"; Layout = "~/Views/Shared/Default.cshtml"; } 错误消息 The view '~/Views/Sth/Sth.cshtml' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Sth/Sth.cshtml ~/Views/Sth/abc.master //string model is threated as a possible Layout's […]

如何在ASP.NET MVC的〜/ Views文件夹下请求静态.html文件?

我希望能够请求位于~/Views文件夹中的静态.html文件。 根据文档,路由系统在评估应用的路由之前检查URL是否与磁盘文件匹配。 但是,当我要求文件404错误出现。 我的文件位于〜/ Views文件夹中。 URL是: http://[localhost]/Views/HtmlPage1.html 我错过了什么?

什么是routes.IgnoreRoute(“{资源} .axd / {* pathInfo}”)

什么是routes.IgnoreRoute("{resource}.axd/{*pathInfo}") 我在我的项目中找不到任何.axd文件,我可以删除此路由规则吗?