I want two CheckBoxList an index view, those CheckBoxList dynamically bind from two different tables. One is Sports and another is Country.
Basically i try through EditorTemplates, but it not working with two models. i face problem to use two model in a single view.
This is my Index Method in Controller
SampleDBContext db = new SampleDBContext();
public ActionResult Index()
{
ViewData["Sports"] = db.Sports.ToList();
ViewData["Country"] = db.Countries.ToList();
return View(ViewData["Sports"]);// I am confused and i don't know what to write there we can call both table data.
}
Template View for Sports
@model MVCDEMO.Models.Sports
@Html.HiddenFor(x => x.s_Id)
@Html.CheckBoxFor(x => (bool)x.is_selected)
@Html.DisplayFor( x => x.s_Name)
Template View for Country
@model MVCDEMO.Models.Country
@Html.HiddenFor(x => x.c_Id)
@Html.CheckBoxFor(x => (bool)x.is_selected)
@Html.DisplayFor( x => x.c_Name)
Index View
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">
Select Sports
</label>
<div class="col-md-3">
@Html.EditorForModel()//what to write it recognize Sports template
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">
Select Country
</label>
<div class="col-md-3">
@Html.EditorForModel()//what to write it recognize Country template
</div>
</div>
</div>
If i work for single Model it work perfectly.