Click here to Skip to main content
15,887,683 members
Home / Discussions / C#
   

C#

 
GeneralRe: Should choose ASP.NET MVC or Xamarin Pin
Richard MacCutchan13-May-15 7:39
mveRichard MacCutchan13-May-15 7:39 
AnswerRe: Should choose ASP.NET MVC or Xamarin Pin
Hitesh Sharma _13-May-15 4:52
Hitesh Sharma _13-May-15 4:52 
GeneralRe: Should choose ASP.NET MVC or Xamarin Pin
Ashfaque Hussain13-May-15 5:45
Ashfaque Hussain13-May-15 5:45 
QuestionC# solving any puzzle with Genetic Algorithms Pin
Member 1168221212-May-15 14:41
Member 1168221212-May-15 14:41 
AnswerRe: C# solving any puzzle with Genetic Algorithms Pin
Sascha Lefèvre12-May-15 15:09
professionalSascha Lefèvre12-May-15 15:09 
QuestionMicrosoft Dynamic AX 2012 Pin
shabeercp11-May-15 19:10
shabeercp11-May-15 19:10 
SuggestionRe: Microsoft Dynamic AX 2012 Pin
Richard MacCutchan11-May-15 21:18
mveRichard MacCutchan11-May-15 21:18 
QuestionMVC3 - Linq query to View Pin
Member 1156707911-May-15 7:25
Member 1156707911-May-15 7:25 
Hi,
I a trying to display a view (MVC3) from two tables using a linq query.

my problem is: When I try to display the view, error:
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[<>f__AnonymousType0`2[LounasAuto.Models.Car,LounasAuto.Models.Cost]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1

My Controller:
public ViewResult Index()
        {
            var carCostLinq = from e in db.Cars
                        join q in db.Costs  on e.CarId equals q.CarId
                        select new {Car = e, Cost = q};


           return View(carCostLinq.ToList());
                   }


first model:
namespace LounasAuto.Models
{
    using System;
    using System.Collections.Generic;
    
    public partial class Car
    {
        public Car()
        {
            this.Locations = new HashSet<Location>();
        }
    
        public int CarId { get; set; }
        public string Plate { get; set; }
        public string ModelDesc { get; set; }
        public string Description { get; set; }
        public int Year { get; set; }
        public string Color { get; set; }
        public string Photo { get; set; }
    
        public virtual ICollection<Location> Locations { get; set; }
        public virtual Cost Cost { get; set; }
    }
}


second model:
namespace LounasAuto.Models
{
    using System;
    using System.Collections.Generic;
    
    public partial class Cost
    {
        public int CarId { get; set; }
        public decimal DailyCost { get; set; }
    
        public virtual Car Car { get; set; }
    }
}


class(model) for show data from both (Cars and Cost)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LounasAuto.Models
{
    public class  CarCost
    {
         
     
        public Car car { get; set; }
        public Cost cost { get; set; }

       
    }
}


and finally my Index.cshtmlview:
@{
    ViewBag.Title = "Index";
}

<h2>Index -- partial _CarList </h2>
 
@Html.Partial("_CarList")


and partial _CarList view:
@model IEnumerable<LounasAuto.Models.CarCost>
@using System.Linq

<table>
    <tr>
        <th>
            Plate
        </th>
        <th>
            ModelDesc
        </th>
        <th>
            Description
        </th>
        <th>
            Year
        </th>
        <th>
            Color
        </th>
        <th>
            Photo
        </th>
        <th></th>
    </tr>



@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.car.Plate)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.car.ModelDesc)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.car.Description)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.car.Year)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.car.Color)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.car.Photo)
        </td>

        <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.car.CarId }) |
            @Html.ActionLink("Details", "Details", new { id = item.car.CarId }) |
            @Html.ActionLink("Delete", "Delete", new { id = item.car.CarId }) ||

           
              @Html.ActionLink("Cost", "Cost", new { id = item.cost.CarId,
                                                     plate = item.car.Plate,
                                                     modelDesc = item.car.ModelDesc,
                                                     description = item.car.Description,
                                                     year = item.car.Year,
                                                     color = item.car.Color,
                                                     all = item.car.Plate + "\n" + item.car.ModelDesc + "\n" + item.car.Description + "\n" + item.car.Year + "\n" + item.car.Color
         })
                     
        </td>
    </tr>
}




</table>
<p>
    @Html.ActionLink("Create New", "Create")
</p>

AnswerRe: MVC3 - Linq query to View Pin
Atish Dipongkor11-May-15 7:48
professionalAtish Dipongkor11-May-15 7:48 
GeneralRe: MVC3 - Linq query to View Pin
Member 1156707911-May-15 7:57
Member 1156707911-May-15 7:57 
AnswerRe: MVC3 - Linq query to View Pin
F-ES Sitecore11-May-15 23:42
professionalF-ES Sitecore11-May-15 23:42 
QuestionUpdate in C# using SQL Server Database. Pin
Norris Chappell10-May-15 19:54
Norris Chappell10-May-15 19:54 
AnswerRe: Update in C# using SQL Server Database. Pin
Agent__00710-May-15 20:27
professionalAgent__00710-May-15 20:27 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell10-May-15 21:03
Norris Chappell10-May-15 21:03 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell10-May-15 21:07
Norris Chappell10-May-15 21:07 
GeneralRe: Update in C# using SQL Server Database. Pin
Agent__00710-May-15 22:12
professionalAgent__00710-May-15 22:12 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell11-May-15 5:49
Norris Chappell11-May-15 5:49 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell11-May-15 6:54
Norris Chappell11-May-15 6:54 
GeneralRe: Update in C# using SQL Server Database. Pin
Mycroft Holmes11-May-15 14:43
professionalMycroft Holmes11-May-15 14:43 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell11-May-15 15:22
Norris Chappell11-May-15 15:22 
GeneralRe: Update in C# using SQL Server Database. Pin
Mycroft Holmes11-May-15 16:09
professionalMycroft Holmes11-May-15 16:09 
AnswerRe: Update in C# using SQL Server Database. Pin
Agent__00711-May-15 17:20
professionalAgent__00711-May-15 17:20 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell11-May-15 20:09
Norris Chappell11-May-15 20:09 
GeneralRe: Update in C# using SQL Server Database. Pin
Agent__00711-May-15 20:30
professionalAgent__00711-May-15 20:30 
GeneralRe: Update in C# using SQL Server Database. Pin
Mycroft Holmes11-May-15 22:32
professionalMycroft Holmes11-May-15 22:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.