TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
lakshmi sowmya
NA
76
102.3k
cannot implicitly convert type to system.collection.generic.
Dec 3 2013 4:20 AM
Hi In our MVC application we need to dispaly data from database in nested repeater..Categories in parent repeater and SubCategories in child repeater.
I tried doing it as follows.
Model:
public class VendorRegistrationStep3
{
public int Category_Id { get; set; }
public string Category_Name { get; set; }
public string Category_Code { get; set; }
public string Description { get; set; }
public bool delete_flag { get; set; }
public IEnumerable<subCategory> subCategoriesList { get; set; }
}
public class VendorRegistrationStep3List
{
public IEnumerable<VendorRegistrationStep3> categoriesList { get; set; }
}
public class subCategory
{
public int Subcategory_Id { get; set; }
public string Subcategory_Name { get; set; }
public string Subcategory_Code { get; set; }
public int categoryId { get; set; }
public string Description { get; set; }
public bool delete_flag { get; set; }
}
Controller :
[HttpGet]
public ActionResult VendorRegistrationStep3()
{
var model = GetCategories();
return View(model);
}
public static IEnumerable<VendorRegistrationStep3List> GetCategories()
{
// Make sure my context gets disposed as soon as I'm done with it.
IEnumerable<VendorRegistrationStep3> categoryList;
using (var db = new bid_portalEntities())
{
// Pull all the questions and answers out in a single round-trip
var Categories = (from objcat in db.bp_category
select new VendorRegistrationStep3
{
Category_Code = objcat.Category_Code,
Category_Name = objcat.Category_Name,
Category_Id = objcat.Category_Id,
subCategoriesList = (from objSubcat in db.bp_subcategory
where objcat.Category_Id == objSubcat.categoryId
select new subCategory
{
Subcategory_Name = objSubcat.Subcategory_Name,
Subcategory_Id = objSubcat.Subcategory_Id,
Subcategory_Code = objSubcat.Subcategory_Code
})
});
categoryList = Categories.AsEnumerable().ToList();
}
return new VendorRegistrationStep3List{ categoriesList = categoryList };
---------Getting Error here
}
View:
<div id="repeater">
@model IEnumerable<AT.Site.BidPortal.Models.VendorRegistrationStep3List>
@foreach (var id in Model)
{
<table>
<tr>
<td width="50">
<input type="image" src="../../Images/Expander.png" size="16px" />
@*<asp:ImageButton ID="PluseBT" runat="server" ImageUrl="~/App_Images/Expander.png"
CommandArgument='<%#Eval("Category_Id") %>' Visible="true" Height="16px" CommandName="_Show"
OnClick="PlusBT_OnClick" />*@
</td>
<td width="350">
<label>
id</label>
I am getting error near Return statement in controller i.e "
Cannot implicitly convert MVC.VendorREgistrationStep3list to System.Collections.generic.Ienumearble<
MVC.VendorREgistrationStep3list>an explicit conversion exists(are you missing any cast)..
I am new to mvc please help me.....
Reply
Answers (
1
)
Redraw C#
WPF Indexed search