Yanor.net/
Wiki
Blog
GitHub
Sandbox
開始行:
* CheckBoxListForプラグイン [#ub602afb]
** 使い方 [#r2e257d9]
http://www.codeproject.com/Tips/613785/How-to-Use-CheckBo...
+ チェックボックスを表すモデルクラスを作る。
+ そのモデルクラスのリスト(配列)を全選択肢のリスト(Ava...
+ ユーザが選択した選択肢を格納するモデルクラス(PostedFru...
+ コントローラーで、PostedFruitsの受け取り処理、DB等から...
+ ビューでCheckBoxListFor()を使用する。
** 使い方の補足 [#tba53b39]
*** 上の使い方のサンプルで出力されるチェックボックスリス...
#sh(html){{
<input id="PostedFruits_FruitIds14" name="PostedFruits.F...
<label for="PostedFruits_FruitIds14">Apple</label>
<input id="PostedFruits_FruitIds15" name="PostedFruits.F...
<label for="PostedFruits_FruitIds15">Banana</label>
<input id="PostedFruits_FruitIds16" name="PostedFruits.F...
<label for="PostedFruits_FruitIds16">Cherry</label>
}}
*** CheckBoxListFor() [#jf2aa4ff]
@Html.CheckBoxListFor(model => model.PostedFruits.FruitI...
model => model.AvailableFruits, ...
fruit => fruit.Id, ...
fruit => fruit.Name, ...
model => model.SelectedFruits, ...
Position.Horizontal)
- (1) この指定により、INPUTタグのNAME属性が<input name="P...
public ActionResult Index(FruitViewModel vm) { var poste...
public ActionResult Index(PostedFruits postedFruits) {}
- (2) チェックボックスの全ての選択肢
- (3) INPUTタグのVALUE属性
- (4) INPUTタグの隣に表示されるLABELタグの文字
- (5) ユーザが選択した値 (List<Fruit>)
-- なお、PostedFruitsはユーザが選択した値、SeelctedFruits...
*** コントローラーでユーザ入力値postedFruitsからCheckBoxL...
/// <summary>
/// for setup view model, after post the user selected f...
/// </summary>
private FruitViewModel GetFruitsModel(PostedFruits poste...
{
// setup properties
var model = new FruitViewModel();
var selectedFruits = new List<Fruit>();
var postedFruitIds = new string[0];
if (postedFruits == null) postedFruits = new PostedF...
// if a view model array of posted fruits ids exists
// and is not empty,save selected ids
if (postedFruits.FruitIds != null && postedFruits.Fr...
postedFruitIds = postedFruits.FruitIds;
}
// if there are any selected ids saved, create a lis...
if (postedFruitIds.Any()) {
selectedFruits = FruitRepository.GetAll()
.Where(x => postedFruitIds.Any(s => x.Id.ToStri...
.ToList();
}
//setup a view model
model.AvailableFruits = FruitRepository.GetAll().ToL...
model.SelectedFruits = selectedFruits;
model.PostedFruits = postedFruits;
return model;
}
** チェックボックスリストをテーブルタグで整形する [#dc333...
http://www.jjask.com/261808/mvc-4-razor-checkboxlistfor-f...
** 参考 [#a5d53bcd]
- Nuget https://www.nuget.org/packages/MvcCheckBoxList
- Project http://mvccbl.com/
- Code Project http://www.codeproject.com/Articles/292050...
終了行:
* CheckBoxListForプラグイン [#ub602afb]
** 使い方 [#r2e257d9]
http://www.codeproject.com/Tips/613785/How-to-Use-CheckBo...
+ チェックボックスを表すモデルクラスを作る。
+ そのモデルクラスのリスト(配列)を全選択肢のリスト(Ava...
+ ユーザが選択した選択肢を格納するモデルクラス(PostedFru...
+ コントローラーで、PostedFruitsの受け取り処理、DB等から...
+ ビューでCheckBoxListFor()を使用する。
** 使い方の補足 [#tba53b39]
*** 上の使い方のサンプルで出力されるチェックボックスリス...
#sh(html){{
<input id="PostedFruits_FruitIds14" name="PostedFruits.F...
<label for="PostedFruits_FruitIds14">Apple</label>
<input id="PostedFruits_FruitIds15" name="PostedFruits.F...
<label for="PostedFruits_FruitIds15">Banana</label>
<input id="PostedFruits_FruitIds16" name="PostedFruits.F...
<label for="PostedFruits_FruitIds16">Cherry</label>
}}
*** CheckBoxListFor() [#jf2aa4ff]
@Html.CheckBoxListFor(model => model.PostedFruits.FruitI...
model => model.AvailableFruits, ...
fruit => fruit.Id, ...
fruit => fruit.Name, ...
model => model.SelectedFruits, ...
Position.Horizontal)
- (1) この指定により、INPUTタグのNAME属性が<input name="P...
public ActionResult Index(FruitViewModel vm) { var poste...
public ActionResult Index(PostedFruits postedFruits) {}
- (2) チェックボックスの全ての選択肢
- (3) INPUTタグのVALUE属性
- (4) INPUTタグの隣に表示されるLABELタグの文字
- (5) ユーザが選択した値 (List<Fruit>)
-- なお、PostedFruitsはユーザが選択した値、SeelctedFruits...
*** コントローラーでユーザ入力値postedFruitsからCheckBoxL...
/// <summary>
/// for setup view model, after post the user selected f...
/// </summary>
private FruitViewModel GetFruitsModel(PostedFruits poste...
{
// setup properties
var model = new FruitViewModel();
var selectedFruits = new List<Fruit>();
var postedFruitIds = new string[0];
if (postedFruits == null) postedFruits = new PostedF...
// if a view model array of posted fruits ids exists
// and is not empty,save selected ids
if (postedFruits.FruitIds != null && postedFruits.Fr...
postedFruitIds = postedFruits.FruitIds;
}
// if there are any selected ids saved, create a lis...
if (postedFruitIds.Any()) {
selectedFruits = FruitRepository.GetAll()
.Where(x => postedFruitIds.Any(s => x.Id.ToStri...
.ToList();
}
//setup a view model
model.AvailableFruits = FruitRepository.GetAll().ToL...
model.SelectedFruits = selectedFruits;
model.PostedFruits = postedFruits;
return model;
}
** チェックボックスリストをテーブルタグで整形する [#dc333...
http://www.jjask.com/261808/mvc-4-razor-checkboxlistfor-f...
** 参考 [#a5d53bcd]
- Nuget https://www.nuget.org/packages/MvcCheckBoxList
- Project http://mvccbl.com/
- Code Project http://www.codeproject.com/Articles/292050...
ページ名: