none
MVC identity 2.0 roles adminUser RRS feed

  • Pregunta

  • estuve viendo unos tutoriales(http://typecastexception.com/post/2014/06/22/ASPNET-Identity-20-Customizing-Users-and-Roles.aspx) para el manejo de roles y usuarios y no me corre el codigo.....tengo problemas en esta parte..

    UserAdminController

    public async Task<ActionResult> Index()
            {
              
               var model = await db.Users.ToListAsync();
                
                return View(model);
            }

    AdminViewModel

    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Web.Mvc;
    
    namespace IdentitySample.Models
    {
        public class RoleViewModel
        {
            public string Id { get; set; }
            [Required(AllowEmptyStrings = false)]
            [Display(Name = "RoleName")]
            public string Name { get; set; }
            public string Description { get; set; }
        }
    
        public class EditUserViewModel
        {
            public string Id { get; set; }
            public string Oficina { get; set; }
            public string NombreCompleto { get; set; }
            [Required(AllowEmptyStrings = false)]
            [Display(Name = "Email")]
            [EmailAddress]
            public string Email { get; set; }
    
            public IEnumerable<SelectListItem> RolesList { get; set; }
        }
    }
    index
    @model IEnumerable<identitysample.models.applicationuser>
                             @{
                                  ViewBag.Title = "Index";
                              }
    
                              <h2>Index</h2>
    
                              <p>
                                  @Html.ActionLink("Create New", "Create")
                              </p>
                              <table class="table">
                                  <tr>
                                      <th>
                                          @Html.DisplayNameFor(model => model.UserName)
                                      </th>
                                      @*<th>
                            @Html.DisplayNameFor(model => model.NombreCompleto)
                        </th>*@
                                      <th>
                                          @Html.DisplayNameFor(model => model.Oficina)
                                      </th>
                                  </tr>
    
                                  @foreach (var item in Model)
                                  {
                                      <tr>
                                          <td>
                                              @Html.DisplayFor(modelItem => item.UserName)
                                          </td>
                                          <td>
                                              @Html.DisplayFor(modelItem => item.NombreCompleto)
                                          </td>
                                          <td>
                                              @Html.DisplayFor(modelItem => item.Oficina)
                                          </td>
                                          <td>
                                              @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
                                              @Html.ActionLink("Details", "Details", new { id = item.Id }) |
                                              @Html.ActionLink("Delete", "Delete", new { id = item.Id })
                                          </td>
                                      </tr>
                                  }
    
                              </table>

    al momento de entrar al index me sale el error

    Server Error in '/' Application.

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

    Compiler Error Message: CS0246: The type or namespace name 'identitysample' could not be found (are you missing a using directive or an assembly reference?)

    Source Error:
    Line 28:     
    Line 29:     
    Line 30:     public class _Page_Views_UsersAdmin_Index_cshtml : System.Web.Mvc.WebViewPage<IEnumerable<identitysample.models.applicationuser>> {
    Line 31:         
    Line 32: #line hidden

    Source File: c:\Users\marcelo\AppData\Local\Temp\Temporary ASP.NET Files\root\9b1fa089\ee0bfabb\App_Web_index.cshtml.3c7f9a0b.almnre4w.0.cs    Line: 30 


    lunes, 22 de diciembre de 2014 22:10

Respuestas

  • Hola...

    c# es case sensitive, es decir, que debes tener en cuenta las mayúsculas y minúsculas.

    en tu Index.cshtml cambia

    @model IEnumerable<identitysample.models.applicationuser>

    por

    @model IEnumerable<IdentitySample.Models.ApplicationUser>
                            


    Si se solucionó tu consulta no olvides marcar la respuesta. Si te ayudó vótala como útil. Saludos

    lunes, 22 de diciembre de 2014 22:40
    Moderador