mvc .net view does not work

0

When I go into the audiologe menu of my .net application I get the following error:

Server error in the application '/'. The model element passed to the dictionary is of type 'System.Collections.Generic.List'1 [serviexpress.auditoria]', but this dictionary requires a model element of type 'serviexpress.audiologeo'. Description: Unhandled exception when executing the current Web request. Check the stack trace for more information about the error and where it originated in the code.

Exception details: System.InvalidOperationException: The model element passed to the dictionary is of type 'System.Collections.Generic.List'1 [serviexpress.auditoria]', but this dictionary requires a type model element ' serviexpress.audiologeo '.

Source code error:

An unhandled exception was generated during the execution of the current Web request. Information about the origin and location of the exception can be identified using the following stack exception.

Tracking the stack:

[InvalidOperationException: The model element passed to the dictionary is of type 'System.Collections.Generic.List'1 [serviexpress.auditoria]', but this dictionary requires a model element of type 'serviexpress.audiologeo'.]

this the audiologeo driver:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using serviexpress.Models;

namespace serviexpress.Controllers
{
public class AudiologeoController : Controller
{
    //
    // GET: /Audiologeo/
    serviexpressEntities2 bdmensajeria = new serviexpressEntities2();

    public ActionResult Index()
    {
        return View(bdmensajeria.auditoria.ToList());
    }

    }
   }

this is the login driver:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net.Mail;
using serviexpress.Models;
using System.Web.Security;
using System.Net;


namespace serviexpress.Controllers
{
public class LoginController : Controller
{
//
// GET: /Login/
serviexpressEntities2 bdmensajeria = new serviexpressEntities2();

public ActionResult Login()
{
return View();
}

// POST: /Login/

[HttpPost]
public ActionResult Login( login UserLog)
{
using (serviexpressEntities2 bdmensajeria = new serviexpressEntities2())
{
var i = (from p in bdmensajeria.usuario
where p.login.Equals(UserLog.usu) && p.contraseña.Equals(UserLog.clave)
select p).FirstOrDefault();
if (i != null)
{
Session["security"] = true;
Session["nombre"] = i.login;
Session["rol"] = i.id_rol;
Session["ingreso"] = DateTime.Now.ToLocalTime();
Session["url"] = HttpContext.Request.Url.AbsoluteUri;
}
else {
ModelState.AddModelError("", "usuario o contraseña incorrectos");
return View();
}
if(Session["rol"].Equals(1)){
return RedirectToAction("Index", "Domicilio");

}
else {
return RedirectToAction("Index", "Contactos");
}

}

}

public ActionResult Logout()
{


audiologeo auditor1 = new audiologeo();
auditor1.login = Session["nombre"].ToString();
DateTime fecha = Convert.ToDateTime(Session["ingreso"]);
auditor1.fecha_ingreso = fecha;
auditor1.fecha_salida = DateTime.Now.ToLocalTime();
auditor1.url = Session["url"].ToString();
bdmensajeria.AddToaudiologeo(auditor1);
bdmensajeria.SaveChanges();
Session.Clear();
return RedirectToAction("Index", "Home");
}

// GET: /Registro/

public ActionResult Registro()
{
return View();
}


// POST: /Registro/

[HttpPost]
public ActionResult Registro(usuario NewUser)
{
try
{
// TODO: Add insert logic here
if (ModelState.IsValid)
{
bdmensajeria.AddTousuario(NewUser);
bdmensajeria.SaveChanges();
}
return RedirectToAction("Index","Home");
}
catch
{
return View();
}
}


}
}

this is the audiology view:

> "% >

    Index

<h2>Index</h2>

<table>
    <tr>
        <th></th>
        <th>
            numero
        </th>
        <th>
            login
        </th>
        <th>
            fecha_ingreso
        </th>
        <th>
            fecha_salida
        </th>
        <th>
            url
        </th>
    </tr>

<% foreach (var item in Model) { %>

    <tr>
        <td>
            <%: Html.ActionLink("Edit", "Edit", new { id=item.numero }) %> |
            <%: Html.ActionLink("Details", "Details", new { id=item.numero })%> |
            <%: Html.ActionLink("Delete", "Delete", new { id=item.numero })%>
        </td>
        <td>
            <%: item.numero %>
        </td>
        <td>
            <%: item.login %>
        </td>
        <td>
            <%: String.Format("{0:g}", item.fecha_ingreso) %>
        </td>
        <td>
            <%: String.Format("{0:g}", item.fecha_salida) %>
        </td>
        <td>
            <%: item.url %>
        </td>
    </tr>

<% } %>

</table>

<p>
    <%: Html.ActionLink("Create New", "Create") %>
</p>

    
asked by ives rodriguez 19.11.2017 в 01:18
source

1 answer

0

You are sending a model of type List<serviexpress.auditoria> but in the view you are waiting for a model of type servexpress.audiologeo . Note that in the model of the view you are waiting for an instance that is not a list, but an object. You have to convert the data you return to the view type servexpress.audiologeo to make it work.

    
answered by 19.11.2017 в 02:32