-1

如何在我的 .cshtml 视图中获取此 url 的最后一部分作为字符串?

http://localhost:10000/BusinessObject/Browse?Name=Game

我需要的值是 Name -> 所以这里是“ Game ”。

键:

"{controller}/{action}/{id}/{name}"

要获取控制器或操作等,我使用以下命令:

Url.RequestContext.RouteData.Values["controller"].ToString();

Url.RequestContext.RouteData.Values["action"].ToString();

但是谁能告诉我如何做类似的事情来获得 Namevalue - “游戏”?

4

1 回答 1

1

假设您在 C# 中的方法如下所示:

    public ActionResult Browse(string Name)
    {
       //Do whatever
       return View()
    }

如果是这种情况,那么您可以将名称放入 ViewBag:

public ActionResult Browse(string Name)
        {
           //Do whatever
           ViewBag.Name = Name;
           return View()
        }

然后在网页上:

<p>@ViewBag.Name<p/>
于 2013-07-11T10:29:44.207 回答