asp.net mvc - How to send a value from a select statement in MVC controller to Viewbag -
i want return value viewbag linq query below
var mycompanyname = (from c in db.companies c.companyid == companyid select c.companyname).tostring(); viewbag.mycompanyname = mycompanyname;
in mvc controller following output in view.
select [extent1].[companyname] [companyname] [dbo].[companies] [extent1] [extent1].[companyid] = @p__linq__0 company name controller action
the result viewbag expected view bag should like: companyname xyz. please how make right?
your not materializing query, , suspect want return single value (not ienumerable<string>
) need replace .tostring()
.firstordefault()
var mycompanyname = (from c in db.companies c.companyid == companyid select c.companyname).firstordefault(); viewbag.mycompanyname = mycompanyname;
or if did want collection of string
, .tolist()
Comments
Post a Comment