问题描述:

I have a UserProfileModel which contains standard profile items plus two List of classes which contain UserLanguages and UserPendingItems. I have seen a number of questions that are similar but do not help me...

UserProfileModels

public class UserProfileModels

{

[Key]

public string UserProfileID { get; set; } // Same as User ID

public string UserProfilePictureURL { get; set; }

public string UserProfileCompanyID { get; set; } // Same as Company ID

// IF UserProfileCompanyID is empty then EU is an individual and the following fields are available

// Else Get the information from the CompanyProfile

public string UserProfileStreet { get; set; }

public string UserProfileTown { get; set; }

public string UserProfileCountry { get; set; } // Allows us to decide on currency, TimeZone, State / County, Post Code / Zip etc

public string UserProfileState { get; set; }

public string UserProfilePostCode { get; set; }

public string UserProfileDOB { get; set; } // Date Of Birth

public string UserProfileSex { get; set; }

public string UserProfileRole { get; set; }

// IF Role is > "Client" then the following fields are to be used.

public string UserProfileTelephoneNumber { get; set; }

public string UserProfileMobileNumber { get; set; }

public List<UserLanguageModels> UserLanguages { get; set; }

public List<UserProfilePendingItems> UserPendingItems { get; set; }

}

UserProfilePendingItems

public class UserProfilePendingItems

{

public string UserProfileID { get; set; }

public string UserProfileDescription { get; set; }

}

UserLanguageModels

public class UserLanguageModels

{

public string UserProfileID { get; set; }

public string UserLanguage { get; set; }

}

In the View there is a dropdown menu which contains a list of the UsersPendingItems

View

<ul class="dropdown-menu extended tasks-bar">

<div class="notify-arrow notify-arrow-green"></div>

<li>

<p class="green">@ViewBag.PendingMessages.Count()</p>

</li>

PROBLEMS BEGIN HERE

@foreach (CCSLABS.Controllers.Administration.AdministrationController.UserProfile Message in ViewBag.PendingMessages)

{

<li>

<a href="index.html#">

<div class="task-info">

<div class="desc">@Message.UserPendingItems.</div>

<div class="percent">40%</div>

</div>

<div class="progress progress-striped">

<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: 40%">

<span class="sr-only">40% Complete (success)</span>

</div>

</div>

</a>

</li>

}

So the idea is within the User's profile we have a list of items that they need to do (Pending Items). Which we send to the View via the ViewBag (There is probably a much better way of doing this!) We Foreach over the ViewBag and create the dropdown menu.

However,

  1. I am going to end up with too much code logic in the view making it a nightmare to maintain.
  2. I can't see the PendingItemsModel within the ViewBag anyway.

Questions

  1. How can I send ONLY the first 4 or 5 PendingItems, that the user has, to the View
  2. How do I create the Iteration of the View List Items to generate the drop down menu using as little code in the view as possible.

相关阅读:
Top