c# - How to get parameters of action of controller from view post -


i have controller action in asp.net mvc application

 public actionresult forfahrzeug(datetime? initdate = null, datetime? finaldate = null, long id = 0, long days = 0, string expgnr = "")     {         //body     } 

i calling above method in view below

 @using (html.beginform("forfahrzeug", "messungen", formmethod.get)) {             <p>fahrten von:       @html.textbox("initdate", "", new { style = "width:15%", @class = "datefield" })  bis:        @html.textbox("finaldate", "", new { style = "width:15%", @class = "datefield" })        <input type="submit" value="filter" /> </p>  }  

i want value of "expgnr" view. how it? tried below not work.

@using (html.beginform("forfahrzeug", "messungen", formmethod.get, new { expgnr = "smart_ed"})) {           fahrten von:       @html.textbox("initdate", "", new { style = "width:15%", @class = "datefield" })  bis:        @html.textbox("finaldate", "", new { style = "width:15%", @class = "datefield" })        <input type="submit" value="filter" /> </p>  }  

i think understand problem. seems choose incorrect overload of method @html.beginform(). should write that:

@using (html.beginform("forfahrzeug", "messungen", new { expgnr = "smart_ed"},formmethod.get)) 

always choose correct overload of mvc extensions or use visualstudio messages it.

and look,is important reason why submit form through method? in cases form should submitted using post request.

and, suppose need use viewmodel form. viewmodel-based solution more clear, extensible , traditionally mvc). can add expgnr property in viewmodel , pass controller through @html.hiddenfor(x => x.expgnr) also, this topic useful you.

update

ok. work:

@using (html.beginform("forfahrzeug", "messungen", formmethod.get)) {            @html.hidden("expgnr","smart_ed")       @html.textbox("initdate", "", new { style = "width:15%", @class = "datefield" })       @html.textbox("finaldate", "", new { style = "width:15%", @class = "datefield" })       <input type="submit" value="filter" />  } 

thank you)


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -