开发者

Grab data from table, join string from two columns, display in MVC selectList

开发者 https://www.devze.com 2023-01-11 09:33 出处:网络
I am new to MVC and LINQ. I have a table with three columns (id, text1, text2).What I want to do is generate a selectList in my view which has DataValue set to table.id, and DataText set to be = text

I am new to MVC and LINQ.

I have a table with three columns (id, text1, text2). What I want to do is generate a selectList in my view which has DataValue set to table.id, and DataText set to be = text1 + ", " + text2; (i.e. join开发者_如何学运维 text1 and text2 with comma separation).

What do you reckon is the best way to achieve this?

Cheers,

Tim.


Something like this perhaps?

var v = dc.threecolumntable.Select(x => new {DataValue = x.id, DataText = x.text1 + ", " + x.text2 })
0

精彩评论

暂无评论...
验证码 换一张
取 消