Model view controller 操作不显示数据

Model view controller 操作不显示数据,model-view-controller,url.action,Model View Controller,Url.action,我正在尝试获取从ActionResult返回到视图的字符串 控制器 public ActionResult GetName(string id) { string returnName; returnName = m_DB.UserProfiles.Find(id).FirstName; return Content(returnName); } 看法 @Action(“GetName”,“UserProfile”,新的{i

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

控制器

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

        return Content(returnName);
    } 
看法

  • @Action(“GetName”,“UserProfile”,新的{id=User.Identity.GetUserId()})
  • 当我运行时,它只是在视图中显示这一点

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


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

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

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


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

    您好,感谢堆的快速响应。但是,当我添加您的代码时,会出现一个错误,即不能隐式地将'void'转换为'object'不能隐式地将'void'转换为'object'@RandikaWijekoon尝试使用第二个Html。Action@RandikaWijekoon很高兴它成功了:)我相信你很快就会掌握窍门的。
     @Html.RenderAction("GetName", "UserProfile", new {id=User.Identity.GetUserId()})
    
     @Html.Action("GetName", "UserProfile", new {id=User.Identity.GetUserId()})