2

i am trying to bind two UserManager Feedback model with one view but i am facing problem in view that a view does not contain any definition for email...here is my all code

public  class FeedbackMixModel
    {

        public List<UserManager> allUserManagers { get; set; }

        public List<Feedback> allfeedbacks { get; set; }

    }

controller==>>>

  var user = db.UserManagers.ToList();
            var feedbacks = db.Feedbacks.ToList();

            var Model = new FeedbackMixModel
            {
                allUserManagers =user,
                allfeedbacks=feedbacks
            };

            return View(Model);

view==>>

@model WebApplication5.Models.FeedbackMixModel


<!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->

        <!-- Main content -->


            <table class="pretty" id="dt">
                <thead>
                    <tr>
                        <th >
                            @Html.DisplayNameFor(model => model.Email)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.CurrentStorage)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.MaxStorage)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.LastLoginMonth)
                        </th>

                    </tr>
                </thead>
                <tbody>
                     @foreach (var item in Model.allUserManagers)
                    {
                        <tr>
                            <td>
                                @Html.DisplayFor(modelItem => item.Email)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.CurrentStorage)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.MaxStorage)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.LastLoginMonth)
                            </td>

                        </tr>
                    }
                </tbody>
            </table>

i am totally confused how to solve this... where Email define in UserManager Class how i can access if i am doing something wrong

The Bearded Llama
  • 3,036
  • 4
  • 20
  • 31
sajiii
  • 172
  • 1
  • 1
  • 8
  • 1
    Your `FeedbackMixModel` does not have an `Email` property. Nor does it have `CurrentStorage`, `MaxStorage` or `LastLoginMonth`. Where are these properties located? – Arthur Rey Jun 29 '16 at 17:31
  • these properties are located in userManager class – sajiii Jun 29 '16 at 17:32

1 Answers1

2

Your actual FeedbackMixModel Model itself doesn't have a definition for the properties that you intend to use for your header :

<thead>
  <tr>
    <th>
      @Html.DisplayNameFor(model => model.Email)
    </th>
    <th>
      @Html.DisplayNameFor(model => model.CurrentStorage)
    </th>
    <th>
      @Html.DisplayNameFor(model => model.MaxStorage)
    </th>
    <th>
      @Html.DisplayNameFor(model => model.LastLoginMonth)
    </th>
  </tr>
</thead>

Your existing Model only contains two properties : allUserManagers and allFeedbacks, so it doesn't know what Email or some of the other properties you are referencing are. Based on your current code, these appear to be actual properties of your UserManager objects and not your actual FeedbackMixModel class.

You could consider hard-coding your header to express these properties :

<thead>
    <tr>
        <th>
          Email
        </th>
        <th>
          Current Storage
        </th>
        <th>
          Max Storage
        </th>
        <th>
          Last Login Month
        </th>
      </tr>
 </thead>

or you could attempt to target the first element in your collection similar to this approach:

<thead>
    <tr>
        <th>
          @Html.DisplayNameFor(x => Model.allUserManagers[0].Email)
        </th>
        <th>
          @Html.DisplayNameFor(x => Model.allUserManagers[0].CurrentStorage)
        </th>
        <th>
          @Html.DisplayNameFor(x => Model.allUserManagers[0].MaxStorage)
        </th>
        <th>
          @Html.DisplayNameFor(x => Model.allUserManagers[0].LastLoginMonth)
        </th>
      </tr>
 </thead>
Community
  • 1
  • 1
Rion Williams
  • 74,820
  • 37
  • 200
  • 327
  • this is the view model contain two others model UserManager and Feedback Email and other properties are defind in UserManager Class is there anyy method to access them??? – sajiii Jun 29 '16 at 17:35
  • You could use an approach similar to the one provided that still uses the `DisplayNameFor()` helper to attempt to resolve the appropriate property names. – Rion Williams Jun 29 '16 at 17:37