|
@* Given *@
<p class="margin_top30">
<h4>Given we have...</h4>
</p>
<p class="margin_top30">
<h5>Base class <code>City</code></h5>
<pre>
public class City {
public int Id { get; set; } // Integer value of a checkbox
public string Name { get; set; } // String name of a checkbox
public object Tags { get; set; } // Object of html tags to be applied to checkbox, e.g.: 'new { tagName = "tagValue" }'
public bool IsSelected { get; set; } // Boolean value to select a checkbox on the list
}
</pre>
<h5>And we use <code>CitiesViewModel</code> view model on our view</h5>
<pre>
public class CitiesViewModel {
public IList<City> AvailableCities { get; set; }
public IList<City> SelectedCities { get; set; }
public PostedCities PostedCities { get; set; }
}
// Helper class to make posting back selected values easier
public class PostedCities {
public string[] CityIDs { get; set; }
}
</pre>
<h5>And our controller accepts class <code>PostedCities</code></h5>
<pre>
public ActionResult Examples(PostedCities postedCities) {
return View(/* Create View Model */);
}
</pre>
</p>
@* end Given *@
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.