Reputation: 385
Im gettting this error in my view on a LinQ Statement of my Model and i dont know why
This is my controller:
namespace Arpon.Web.Brain.Pos.Models
{
public class HomePosController : BaseController
{
public ActionResult Index(string txtInput)
{
return View("~/Views/HomePos/Index.cshtml",db.VENTA_PLATILLOS.ToList());
}
}
}
This is my Model
namespace Arpon.Web.Brain.Pos.Models
{
public partial class VENTA_PLATILLOS
{
public System.DateTime Fecha { get; set; }
public string Clave_PDV { get; set; }
public int Cheque { get; set; }
public int Linea { get; set; }
public int Platillo { get; set; }
public string Nombre_Platillo { get; set; }
public string Tipo { get; set; }
public int Cantidad { get; set; }
public decimal Precio { get; set; }
public decimal Total { get; set; }
public int Turno { get; set; }
public string Nombre_Turno { get; set; }
public int Grupo { get; set; }
public string Nombre_Grupo { get; set; }
public string Nombre_Pdv { get; set; }
public string Estatus_Pla { get; set; }
public string Estatus_Che { get; set; }
}
}
And my View::
@model ICollection<Arpon.Web.Brain.Pos.Models.VENTA_PLATILLOS>
<!--other code-->
<select>
<option value="">Todos</option>
@foreach (var item in Model.Select(l => l.Nombre_Pdv).OrderByDescending(a=>a.Length).Distinct())
{
<option value="@item">@item</option>
}
</select>
Im getting The folling error at the 'Model.' part "The type argument for method cannot be inferred from usage" What i am doing wrong?
UPDATED
I solved the Problem Changing my model declaration 'ICollection' to 'List'
@model List<Arpon.Web.Brain.Pos.Models.VENTA_PLATILLOS>
Upvotes: 0
Views: 804
Reputation: 660
The issue could be that your loop does not know what 'Type' it is iterating. Try using an explicit cast.
@foreach (var item in (List<string>) Model.Select(l => l.Pdv).OrderByDescending(a=>a.Length).Distinct())
Upvotes: 1