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 subCategoriesList { get; set; }
}
public class VendorRegistrationStep3List
{
public IEnumerable 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 GetCategories()
{
// Make sure my context gets disposed as soon as I'm done with it.
IEnumerable 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:
@model IEnumerable
@foreach (var id in Model)
{
@* CommandArgument='<%#Eval("Category_Id") %>' Visible="true" Height="16px" CommandName="_Show" OnClick="PlusBT_OnClick" />*@ | id 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..... 1 ReplyKnow the answer? Post it — somebody with the same question will find it here. Sign in to answer this question It is the same account you read, post and publish with — and you will come straight back to this page. |
Dharmendra SinghPosted Dec 3, 2013, 6:43 AM
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
}).AsEnumerable().ToList()
});
hope this help you