c# - Passing a value, retrieved from a linq statement in a view, to its controller -


i have view has c# , linq in it(not ideal have work it!):

protected void page_load(object sender, eventargs e) {  .  . var qry = (from p in db.entityobject                        == something_else                        select new                             {                                 <fields>                             }).firstordefault();  .  . } <asp:content id="content2" contentplaceholderid="maincontent" runat="server"> . . 

i need pass value retrieved via linq statement in view controller. i've tried this:

 var qry = (from <entity objects>         select new                         {                             id,                             // fields                         }).firstordefault();  routedata.values.add("id", qry.id); 

then tried pass hidden input type value:

<input type="hidden" value="<%int32.parse(routedata.values["id"].tostring())"/> 

but, when use chrome's tools view input element 'value' empty. don't know of way pass field retrived linq in view it's corresponding action in controller.

my view typed based on table in entity framework , 'id' want pass, view controller, not in table. don't want create model, 1 field, unless have to.

how can this?

i may misunderstanding question, looks you're trying obtain value in view , make value available code running in controller. view has handle controller through viewcontext.controller, can cast type of controller , interact with. example, add property controller , set view. i'm not sure why that, because controller's job done time view rendering, it's option if want pursue it.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -