小编Joh*_*Doe的帖子

RoutePrefix不起作用Asp.NET MVC

RoutePrefix对我不起作用。

控制者

[RoutePrefix("example-name")]
public class HomeController : Controller
{
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";

            return View();
        }
}
Run Code Online (Sandbox Code Playgroud)

路由配置

public static void RegisterRoutes(RouteCollection routes)
{
       routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

       routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
       routes.MapMvcAttributeRoutes();
}
Run Code Online (Sandbox Code Playgroud)

索引页

 @Html.ActionLink("click me", "index","example-name");
Run Code Online (Sandbox Code Playgroud)

我已经完成了所有基本步骤,但是我没有得到404

无法找到该资源。

的版本System.Web.Mvc.dll是5.2.3.0

c# asp.net-mvc routing attributes

5
推荐指数
2
解决办法
6023
查看次数

显示每个页面的标题 ASP.NET MVC

我有一个布局页面,它有一个标题,其余页面都有自己的标题,我想在浏览器中为用户访问的每个页面显示标题。目前它显示布局页面的标题。

布局页

<title>page layout tile</title>
Run Code Online (Sandbox Code Playgroud)

每个子页面

子页面

<head>
    <meta name="viewport" content="width=device-width" />
    <title>Download Me</title>
</head>
Run Code Online (Sandbox Code Playgroud)

浏览器显示每个页面的布局页面标题。

我的努力

布局页面的标题中没有提供任何描述,则浏览器默认将页面的 url 显示为标题

布局页

<title></title>
Run Code Online (Sandbox Code Playgroud)

html asp.net-mvc page-title

2
推荐指数
1
解决办法
4691
查看次数

我如何声明一个名为static的类

我重命名了一个名为static的类,我有编译时错误

public class static
    {

    }
Run Code Online (Sandbox Code Playgroud)

错误CS0116命名空间不能直接包含诸如字段或成员之类的成员

c# class classname

0
推荐指数
1
解决办法
79
查看次数

标签 统计

asp.net-mvc ×2

c# ×2

attributes ×1

class ×1

classname ×1

html ×1

page-title ×1

routing ×1