ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Dynamically generating columns based on received data
Title:
B
I
{code}
?
Hi I want to dynamically map all the columns whichever property field I receive from my wcf service. Like I don't want to use "Map = o => new": for eg:- var list = Db.Lunches .Where(o => o.Food.ToLower().Contains(food) && o.Person.ToLower().Contains(person)) .AsQueryable(); if (country.HasValue) list = list.Where(o => o.Country.Id == country); return Json(new GridModelBuilder<Lunch>(list, g) { Key = "Id", // needed for Entity Framework | nesting | tree | api Map = o => new { o.Id, } o.Person, } o.Food, } o.Location, } ----------------------- I don't want this mapping o.Price, } instead all the properties which o.Date, } list contains should be mapped CountryName = o.Country.Name, } automatically and I should be able to ChefName = o.Chef.FirstName + " " + o.Chef.LastName } generate all columns based on this } }.Build()); Please suggest !!
Save Changes
Cancel
Tanuj Shrivastava
asked at 20 Jul 2016
not really sure what you need here
at 20 Jul 2016
Omu
I am asking whether mapping is mandatory for every field coming in list. As I don't want it
at 20 Jul 2016
Tanuj Shrivastava
depends on your situation, it's not mandatory, have you tried without it ?
at 20 Jul 2016
Omu
yes, but I don't want to bind the columns either, on the view. Will the columns generate automatically
at 20 Jul 2016
Tanuj Shrivastava
it can be done, have a look at this demo: http://demo.aspnetawesome.com/GridArrayDataSource in the controller code the columns are generated in a for loop
at 20 Jul 2016
Omu
Answers
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK