[英]Asp.Net MVC - returing pure ViewModel from controller action
我使用Asp.Net MVC 5.0,並且想在布局頁面中與控制器“交談”。 我想打電話給ProfileController.GetProfileInformationViewModel
在我的布局頁方法來獲得ProfileViewModel
類對象。 是否可以不返回ActionResult
( View/PartialView
)並在Razor中使用類似HtmlAction
的方法? 我不想返回任何html,我想保持它解耦和可重用。
您是說要返回JSON數據之類的內容並通過JavaScript來獲取它嗎?
public JsonResult GetProfileInformationViewModel(int id)
{
var myProfile = GetProfile(id);
return new JsonResult(){ Data = myProfile };
}
然后,您可以使用ajax調用來獲取對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.