我试图从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>
当我跑步时,它只是在视图中显示了这个
/用户配置/的GetName / 7781341a-ab1b-4b1d-b75b-853376690bf4
我想要的只是显示用户的名字。我究竟做错了什么?请帮忙。我感谢你的贡献。
答案 0 :(得分: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
获取您提供的参数并构建网址,而@Html.RenderAction
在调用它的视图中将内嵌操作的结果呈现为内嵌。