如何从控制器返回剃刀页面?

时间:2019-07-02 21:01:59

标签: asp.net-core razor controller

简单地做:

var result = db.OrgStructures
    .Where(e => e.FiscalYear == 19)
    .Select(org => new OrgStructureModel 
    {
        NodeId = org.NodeId,
        ParentNodeId = org.ParentNodeId,
        Name = org.Name,
        DepartmentCode = org.DepartmentCode,
        Acronym = org.Acronym,
        LegacyId = org.LegacyId,
        // Notice using "Any" method instead of comparing count with 0
        hasChildren = db.OrgStructures.Any(s => s.ParentNodeId == org.NodeId),
    })
    .ToList();

给出错误[HttpGet("{id}", Name = "Get")] public ActionResult Get(int id) { var result = new Pages.IndexModel().Page(); result.ViewData["ID"] = id; return result; }

我只想将数据传递到页面并查看它。

1 个答案:

答案 0 :(得分:1)

我发现它甚至不需要控制器。

在.cshtml中,在顶部@page "{id:int?}"处添加

然后稍后再做

<p>@RouteData.Values["id"].ToString()</p>