【问题标题】:How does this code work ASP .NET MVC? [closed]此代码如何在 ASP .NET MVC 中工作? [关闭]
【发布时间】:2014-02-22 16:45:49
【问题描述】:

我正在阅读 Adam 的书 Pro ASP .NET MVC 4,我有一个问题,这段代码是做什么用的?

@Html.RouteLink(link, new
    {
        controller = "Product",
        action = "List",
        category = link,
        page = 1
    },
    new {
        @class = link == ViewBag.SelectedCategory ? "selected" : null
    })

另外,我有一个控制器,里面有方法

public PartialViewResult Menu(string category = null)
{
            ViewBag.SelectedCategory = category;
            IEnumerable<string> categories = repository.Products
              .Select(x => x.Category)
              .Distinct()
              .OrderBy(x => x);
            return PartialView(categories);
}

感谢您的帮助!

【问题讨论】:

  • 你必须在 google/bing 中做一些关于 PartialViews 和 Routelink 的研究。

标签: c# asp.net-mvc asp.net-mvc-routing


【解决方案1】:

引用MSDN:

RouteLink 返回一个锚元素(一个元素),其中包含 指定动作的虚拟路径。

表示会在html后面生成一个标签

<a href="myserver/Product/List...">linkstring</a>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多