Prabu Spark

Prabu Spark

  • NA
  • 124
  • 203k

The model item passed into the dictionary is of type ?

Apr 28 2014 7:08 AM
Hi sir,

I am getting the error "The model item passed into the dictionary is of type but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable". I shared my Model, View and controller for your reference. In that view, i need to display all the records from the database. Kindly give me the solution for this problem.



Model:

************


namespace JobPortal.Models
{
public class UserDetails
{
[Required(ErrorMessage="Name required")]
[StringLength(50,MinimumLength=5,ErrorMessage="Name must between 5 and 50 characters")]
[Display(Name="Name")]
// [DataType(DataType.Text)]
public string name { get; set; }

[Required(ErrorMessage="Age required")]
[StringLength(3,MinimumLength=1,ErrorMessage="Age must between 1 and 100")]
[Display(Name="Age")]

public string age{ get; set; }

[Required(ErrorMessage="Date of Birth required")]
[Display(Name="Date of Birth")]
[DataType(DataType.Date)]
public string dob { get; set; }

[Required(ErrorMessage="Sex required")]
[Display(Name="Sex")]
[DataType(DataType.Text)]
public string sex { get; set; }



[Display(Name="Religion")]
[DataType(DataType.Text)]
public string religion { get; set; }


[Display(Name="Caste")]
[DataType(DataType.Text)]
public string caste { get; set; }

[Required(ErrorMessage="Father's Name required")]
[StringLength(50,MinimumLength=5,ErrorMessage="Father's Name must between 5 and 50 characters")]
[Display(Name="Father's Name")]
[DataType(DataType.Text)]
public string fathername { get; set; }

[Required(ErrorMessage="Occupation required")]
[StringLength(50,MinimumLength=3,ErrorMessage="Occupation must between 3 and 50 characters")]
[Display(Name="Occupation")]
[DataType(DataType.Text)]
public string occupation { get; set; }

[Required(ErrorMessage="Graduation required")]
[Display(Name="Graduation")]
[DataType(DataType.Text)]
public string graduation { get; set; }



[Required(ErrorMessage = "Address required")]
[Display(Name = "Address")]
[DataType(DataType.MultilineText)]
public string address { get; set; }

[Required(ErrorMessage = "Mobile No. required")]
[Display(Name = "Mobile No.")]
[DataType(DataType.PhoneNumber)]
public string mobileno { get; set; }

[Required(ErrorMessage="Username required")]
[StringLength(50,MinimumLength=5,ErrorMessage="Username must between 5 and 50 characters")]
[Display(Name="Username")]
[DataType(DataType.Text)]
public string username { get; set; }

[Required(ErrorMessage="Password required")]
[StringLength(50,MinimumLength=5,ErrorMessage="Password must between 5 and 50 characters")]
[Display(Name="Password")]
[DataType(DataType.Password)]
public string password { get; set; }


[Required(ErrorMessage = "Repeat Password required")]
[Compare("password", ErrorMessage = "The new password and confirmation password do not match.")]
[StringLength(50, MinimumLength = 5, ErrorMessage = "Repeat Password must between 5 and 50 characters")]
[Display(Name = "Password Repeat")]
[DataType(DataType.Password)]
public string passwordrepeat { get; set; }


[Required(ErrorMessage = "Email ID required")]
[Display(Name="Email ID")]
[DataType(DataType.EmailAddress)]
public string emailid { get; set; }


public DataSet RetrieveAllData { get; set; }

}
}

Controller:

***************

public ActionResult ShowData(UserDetails ur)
{
DB.JobSeekerDB a1 = new DB.JobSeekerDB();
ur.RetrieveAllData = a1.RetrieveAllInfo();
return View(ur);

}





View:

*************



@model IEnumerable<JobPortal.Models.UserDetails>

@{
ViewBag.Title = "ShowData";
}

<h2>ShowData</h2>

<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th></th>
<th>
name
</th>
<th>
age
</th>
<th>
dob
</th>
<th>
sex
</th>
<th>
religion
</th>
<th>
caste
</th>
<th>
fathername
</th>
<th>
occupation
</th>
<th>
graduation
</th>
<th>
address
</th>
<th>
mobileno
</th>
<th>
username
</th>
<th>
password
</th>
<th>
passwordrepeat
</th>
<th>
emailid
</th>
</tr>

@foreach (var item in Model) {
<tr>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
<td>
@item.name
</td>
<td>
@item.age
</td>
<td>
@item.dob
</td>
<td>
@item.sex
</td>
<td>
@item.religion
</td>
<td>
@item.caste
</td>
<td>
@item.fathername
</td>
<td>
@item.occupation
</td>
<td>
@item.graduation
</td>
<td>
@item.address
</td>
<td>
@item.mobileno
</td>
<td>
@item.username
</td>
<td>
@item.password
</td>
<td>
@item.passwordrepeat
</td>
<td>
@item.emailid
</td>
</tr>
}

</table>