title: How to determine selected value for drop down lists in asp.net MVC View?
body: <p>New to asp.net MVC.  I have a table that has multiple fields.  I want to build input rules where the user has to select a value either in Field1's or Field2's drop down list.  The user will not be able to post if a value is selected for both Field1 and Field2 simultaneously or if neither Field1 or Field2 have a selected value. </p>
  
  <p>Part of my dilemma is in deciding where the input logic or rules should be recorded (Controller vs View)?  As I understand it, best practice is to keep the Controller simple and "skinny" so do I place the input rules in the View using Razor?  If so, how?</p>
  
  <p>Thank you in advance for your suggestions.</p>
  
  <p>Here is the model:</p>
  
  <pre><code>public class Order
  {
      public int OrderID {get; set;} 
      public string Field1 {get; set;} 
      public string Field2 {get; set;} 
      //other properties 
  }                                                        
  </code></pre>
  
  <p>I use viewbags in the Controller to create the dropdownlists:</p>
  
  <pre><code>// GET: Order/Create
  public ActionResult Create()
  {
       ViewBag.Field1 = new SelectList(db.Field1.OrderBy(x =&gt; x.Name), "Name", "Name");            
       ViewBag.Field2 = new SelectList(db.Field2.OrderBy(z =&gt; z.Clip), "Clip", "Clip");            
       return View();
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
       @Html.LabelFor(model =&gt; model.Field1, htmlAttributes: new { @class = "control-label col-md-2" })
       &lt;div class="col-md-10"&gt;
           @Html.DropDownListFor(model =&gt; model.Field1, (SelectList)ViewBag.Field1, "Select one...", htmlAttributes: new { @class = "form-control" })
           @Html.ValidationMessageFor(model =&gt; model.Field1, "", new { @class = "text-danger" })                
        &lt;/div&gt;
  &lt;/div&gt;                                                               
  &lt;div class="form-group"&gt;
       @Html.LabelFor(model =&gt; model.Field2, htmlAttributes: new { @class = "control-label col-md-2" })
       &lt;div class="col-md-10"&gt;
           @Html.DropDownListFor(model =&gt; model.Field2, (SelectList)ViewBag.Field2, "Select one...", htmlAttributes: new { @class = "form-control" })
           @Html.ValidationMessageFor(model =&gt; model.Field2, "", new { @class = "text-danger" })                
       &lt;/div&gt;
   &lt;/div&gt; 
  </code></pre>