Raza Jamil
Raza Jamil

Reputation: 274

unable to pass a list from viewmodel in a view to a partial view

Basically I have a view model

public class VM_MachineCheckSheet
{        
    public List<checksheet> checksheet;
    public List<MvcApplication2.Models.Machine.machine> machine;
}

My main View

@model MvcApplication2.Models.CheckSheet.VM_MachineCheckSheet

@{
    ViewBag.Title = "MachineCheckSheet";
}

@Html.RenderPartial("_MachineCheckBoxListPartial", Model.machine);

and my Partial View

@model IEnumerable&ltMvcApplication2.Models.Machine.machine&gt

<div id = "machine_filter" class = "machine_filter")
<table>
    <tr>

I populate the viewmodel in my controller then pass it to the main view and then pass only machine to the partial view which is strongly typed with IEnumerable&ltmachine&gt

this is the error i get

Compiler Error Message: CS1502: The best overloaded method match for 
'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)
'has some invalid arguments

Line 7:  @Html.RenderPartial("_MachineCheckBoxListPartial", Model.machine);

I don't know why there is a type mismatch between List of machine in the partial view and the one being passed in from the view model. They are the same thing. Any ideas?

Upvotes: 2

Views: 418

Answers (1)

Nitin Varpe
Nitin Varpe

Reputation: 10694

You need to change

@Html.RenderPartial("_MachineCheckBoxListPartial", Model.machine);

To

@{ Html.RenderPartial("_MachineCheckBoxListPartial", Model.machine); }

FOR MORE

Upvotes: 2

Related Questions