Hi!
I have two models in one-more relation: One "Region" to more "Punkt"
I'am using ASP.NET MVC4 and have Edit page of "Punkt" Model record. The Edit page has ComboBox populated with Regions but which I have to set to adequate Region (where Punkt belongs to).
The problem: I don't know how to set ComboBox to adequate Punkt option.
Here is PunktController:
Here is Edit.cshtml view:
I have two models in one-more relation: One "Region" to more "Punkt"
I'am using ASP.NET MVC4 and have Edit page of "Punkt" Model record. The Edit page has ComboBox populated with Regions but which I have to set to adequate Region (where Punkt belongs to).
The problem: I don't know how to set ComboBox to adequate Punkt option.
Here is PunktController:
// GET: /Punkt/Edit/5public ActionResult Edit(int id = 0){ Punkt punkt = db.Punktovi.Find(id); if (punkt == null) { return HttpNotFound(); } ViewBag.MaticniRegionId = new SelectList(db.Regioni, "RegionId", "Name", punkt.MaticniRegionId); return View(punkt);}
//THIS IS MY METHOD USED FOR POPULATING COMBOBOX (SEE: EDIT view)
public ActionResult getRegioni()
{
if (Request.IsAjaxRequest())
{
var ISPISContext = new ISPISContext();
return Json(ISPISContext.Regioni.Select(r => new { RegionId = r.RegionId, Name = r.Name }), JsonRequestBehavior.AllowGet);
}
return View();
}
Here is Edit.cshtml view:
@(Html.Kendo().ComboBox() .Name("MaticniRegionId") .Placeholder("Select region...") .DataTextField("Name") .DataValueField("RegionId") .DataSource(source => { source.Read(read => { read.Action("getRegioni", "Punkt"); }); }) .Suggest(true))