List types and conversions [Resolved]

Posted by Rasagna under ASP.NET MVC on 3/9/2016 | Points: 10 | Views : 1993 | Status : [Member] | Replies : 2
how to convert list<model>abc to ienumerable<selectlistitem>abc type. in a controller where
model:

public class model
{ public guid id,
public string name,
public Ienumerable<selectlistitem> abc
}


where abc is a table which contains records with abcid,abcname as columns which must be mapped to model.id,model.name
ie abcid = model.id,abcname=model.name




Responses

Posted by: Sheonarayan on: 3/12/2016 [Administrator] HonoraryPlatinum | Points: 50

Up
1
Down

Resolved
Create List<SelectListItem> variable and iterate through each List<model> and ad into List<SelectListItem>.
 new SelectListItem() { Text= model.Text, Value = model.value }

By default List inherit IEnumerable behavior.

Read this article, this will help you a lot http://www.dotnetfunda.com/articles/show/2918/working-with-dropdownlist-in-aspnet-mvc

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Rasagna, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 3/9/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
@Rasagna Sir, why don't you give a try with Automapper .

Kindly follow this article ( http://csharppulse.blogspot.in/2013/08/crud-operations-using-automapper-in-c_381.html )

And let us know in case you need further assistance.

Thanks

--
Thanks & Regards,
RNA Team

Rasagna, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response