Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I personally use ViewBag &amp; ViewData to solve this condition.</p> <p>Controller:</p> <pre><code>public ActionResult Index() { ViewBag.dd1value = default_value; ViewBag.dd1 = DropDownlist1(); ViewBag.dd2 = DropDownlist2(dd1value); Return View(); } </code></pre> <p>View:</p> <p>In the first dropdownlist add an onchange javascript.</p> <pre><code>&lt;select onchange="javascript:this.form.submit();"&gt; @foreach (var item in ViewBag.dd1) { if (ViewBag.dd1value = item.dd1value) { &lt;option selected value="@item.dd1value"&gt;@item.dd1text&lt;/option&gt; } else { &lt;option value="@item.dd1value"&gt;@item.dd1text&lt;/option&gt; } } </code></pre> <p>Then, on submit button give it a name.</p> <pre><code>&lt;input type="submit" name="Genereate" value="Generate" /&gt; </code></pre> <p>In the controller, create 2 ActionResult to receive data. For dropdownlist:</p> <pre><code>[HttpPost] public ActionResult Index(int dd1value) { ViewBag.dd1value = dd1value; ViewBag.dd1 = DropDownlist1(); ViewBag.dd2 = DropDownlist2(dd1value); Return View(); } </code></pre> <p>For submit button:</p> <pre><code>[HttpPost] public ActionResult Index(int dd1value, int dd2value, FormCollection collection) { ViewBag.dd1value = dd1value; ViewBag.dd2value = dd2value; ViewBag.dd1 = DropDownlist1(); ViewBag.dd2 = DropDownlist2(dd1value); ViewBag.result = Result(dd1value, dd2value); Return View(); } </code></pre> <p>If you don't need button:</p> <pre><code>[HttpPost] public ActionResult Index(int dd1value, int dd2value) { ViewBag.dd1value = dd1value; ViewBag.dd2value = dd2value; ViewBag.dd1 = DropDownlist1(); ViewBag.dd2 = DropDownlist2(dd1value); ViewBag.result = Result(dd1value, dd2value); Return View(); } </code></pre> <p>Please note that if you use ViewBag / ViewData, all the help you get from the compiler is disabled and runtime errors/bugs will occur more likely than if the property has been on a "normal" object and typos would be catched by the compiler.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload