[英]asp.net mvc 3 razor Two controllers in one view
Want to use two models in one view. 想要在一个视图中使用两个模型。 I have two controllers one for current user
我有两个控制器,一个用于当前用户
public class ProfileModel
{
public int ID { get; set; }
public decimal Balance { get; set; }
public decimal RankNumber { get; set; }
public decimal RankID { get; set; }
public string PorfileImgUrl { get; set; }
public string Username { get; set; }
}
and second for firends 第二个朋友
public class FriendsModel
{
public int ID { get; set; }
public string Name { get; set; }
public string ProfilePictureUrl { get; set; }
public string RankName { get; set; }
public decimal RankNumber { get; set; }
}
Profile model contains always one item and Friend model contains list 个人档案模型始终包含一个项目,而朋友模型包含列表
I have made new model which contains both models : 我制作了包含两个模型的新模型:
public class FullProfileModel
{
public ProfileModel ProfileModel { get; set; }
public FriendsModel FriendModel { get; set; }
}
I tried to fill FullProfile model like this 我试图像这样填充FullProfile模型
List<FriendsModel> fmList = GetFriendsData(_UserID);
FullProfileModel fullModel = new FullProfileModel();
fullModel.ProfileModel = pm;
fullModel.FriendModel = fmList.ToList();
but visual studio gives an error on .ToList() 但是Visual Studio在.ToList()上给出了错误
error: 错误:
Cannot implicitly convert type 'System.Collections.Generic.List<NGGmvc.Models.FriendsModel>' to 'NGGmvc.Models.FriendsModel'
Please advice me something how i can show two models in single view. 请给我一些建议,我如何在单个视图中显示两个模型。
ps im using mvc3 razor view engine ps im,使用mvc3剃刀视图引擎
Thanks 谢谢
Correct your ViewModel 更正您的ViewModel
public class FullProfileModel
{
public ProfileModel ProfileModel { get; set; }
public IList<FriendsModel> FriendModels { get; set; }
}
I think you need collection 我想你需要收藏
public class FullProfileModel
{
public ProfileModel ProfileModel { get; set; }
public List<FriendsModel> FriendModels { get; set; }
}
You are trying to set a property of type FriendsModel with a value of List. 您试图设置类型为List的FriendsModel类型的属性。
public FriendsModel FriendModel { get; set; }
Change to: 改成:
public class FullProfileModel
{
public ProfileModel ProfileModel { get; set; }
public IList<FriendsModel> FriendModel { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.