1

我试图获取从 ActionResult 返回到视图的字符串

控制器

public ActionResult GetName(string id)
    {
        string returnName;
        returnName = m_DB.UserProfiles.Find(id).FirstName;

        return Content(returnName);
    } 

看法

    <li>
       @Url.Action("GetName", "UserProfile", new {id=User.Identity.GetUserId()})

    </li>   

当我运行时,它只是在视图中显示

/UserProfile/GetName/7781341a-ab1b-4b1d-b75b-853376690bf4

我想要的只是显示用户的名字。我究竟做错了什么?请帮忙。我感谢你的贡献。

4

1 回答 1

1

我认为您正在寻找的方法是@Html.RenderAction@Html.Action

 @Html.RenderAction("GetName", "UserProfile", new {id=User.Identity.GetUserId()})

或者

 @Html.Action("GetName", "UserProfile", new {id=User.Identity.GetUserId()})

@Url.Action获取您提供给它的参数并构建一个 url,同时@Html.RenderAction在调用它的视图中呈现内联操作的结果。

于 2014-10-17T21:50:26.987 回答