我想單獨的朋友facebook和twitter。 像這樣:asp.net mvc3,c#
Twitter的Facebook的
EditorTemplates:FriendModel.cshtml
@model App.Web.Models.FriendModel
<div>
<input type="checkbox" name="saveInputs" value="@Model.FriendID"/>
<img alt="" src="@Model.ProfileImageUrl" />
<strong>@Model.Name</strong> Friends: <strong>@Model.FriendsCount</strong>
</div>
<br />
瀏覽:FriendTeam.cshtml
@model App.Web.Models.FriendTeamModel
@{
ViewBag.Title = "FriendTeam";
}
<h2>
FriendTeam</h2>
@using (@Html.BeginForm())
{ @Html.ValidationSummary(true)
<h3>Twitter</h3>
<br />
@Html.EditorFor(model => model.Friends.Where(x=>x.SocialNetworkName=="Twitter"))
<h3>Facebook</h3>
<br />
@Html.EditorFor(model => model.Friends.Where(x=>x.SocialNetworkName=="Facebook"))
}
<div>
@Html.ActionLink("Back to List", "Index")
FriendTeamModel:
public class FriendTeamModel
{
public long FriendTeam{ get; set; }
public IEnumerable<FriendModel> Friends { get; set; }
}
FriendModel:
public class FriendModel
{
public string FriendID { get; set; }
public string SocialNetworkName { get; set; }
public string Name { get; set; }
public int FriendsCount { get; set; }
public string ProfileImageUrl { get; set; }
}
錯誤:
模型只能用於房屋所有權的表達式訪問字段,一維數組索引或自定義索引器單一參數。
感謝,
我會在這裏使用一個視圖模型1的IEnumerable對Twitter和一個爲Facebook這樣的拆分在控制器完成的,而不是視圖 –
Manatherin