sajiii
sajiii

Reputation: 172

ViewModel does Not contain definition for Email

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

Upvotes: 2

Views: 651

Answers (1)

Rion Williams
Rion Williams

Reputation: 76597

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>

Upvotes: 2

Related Questions