c# - get selected value from @HtmlDropDown -


so values drop down list wanted selected value dropdown. how ?

model:

  public partial class region {     public int id_regionu { get; set; }     public string nazwa { get; set; } } 

controller:

    public class homecontroller : controller {       private inzs9776entities db = new inzs9776entities();     protected override void dispose(bool disposing)     {         db.dispose();         base.dispose(disposing);     }     public actionresult index()     {         viewbag.regiony = new selectlist(db.region,"id_regionu", "nazwa");         return view();     } 

and view dropdown:

  <div class="jumbotron">     <legend>         <h2>wyszukaj wycieczkÄ™</h2></legend><br/>     <form action="">         <div class="container">             wybierz kierunek:             @html.dropdownlist("regiony",null, string.empty)<br />             data wyjazdu:             <input class="date" type="date" name="startdate"><br><br>         </div>     </form> 

`

replace <form action=""> to:

@using (html.beginform("myactionname") {     // ...       //here add dropdown , give name     @html.dropdownlist("regiony", null, string.empty)     // ... } 

the name attribute of <select> element (dropdown list) "regiony".

in controller:

public actionresult myactionname(string regiony) {    // here regiony variable contains selected value.    // ... } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -