S
shapper
Hello,
I am trying to display a DropDownList on an ASP.NET MVC view.
SlidePaper.Targets contains the list of items and
SlidePaper.Slide.Target contains the current value taken from the
database for the given record ...
This works but does not give the current value, only the list:
<%= Html.DropDownList(null, "Targets") %> .
Then do display the list and the current value I tried the following:
<%= Html.DropDownList(null, (string)ViewData["Target"] ??
ViewData.Model.SlidePaper.Slide.Target.ToString(),
(SelectList)ViewData["Targets"])%>
It gives an error:
Value cannot be null.
Parameter name: selectList
Use the "new" keyword to create an object instance
I don't know how to solve this. Could someone, please, help me out?
On my controller I have:
public ActionResult Create() {
SlideViewData viewData = new SlideViewData();
viewData.Targets = Asset.Targets();
viewData.SlidePaper.Slide.Target = "_blank";
return View("Create", viewData);
}
I am testing this on my Create view but as you can see I am defining
Targets and Target.
Asset.Targets is:
public static SelectList Targets() {
var targets = new Dictionary<string, string>();
targets.Add("Blank", "_blank");
targets.Add("Parent", "_parent");
targets.Add("Self", "_self");
targets.Add("Top", "_top");
var list = new SelectList(targets, "Value", "Key");
return list;
}
Thank You,
Miguel
I am trying to display a DropDownList on an ASP.NET MVC view.
SlidePaper.Targets contains the list of items and
SlidePaper.Slide.Target contains the current value taken from the
database for the given record ...
This works but does not give the current value, only the list:
<%= Html.DropDownList(null, "Targets") %> .
Then do display the list and the current value I tried the following:
<%= Html.DropDownList(null, (string)ViewData["Target"] ??
ViewData.Model.SlidePaper.Slide.Target.ToString(),
(SelectList)ViewData["Targets"])%>
It gives an error:
Value cannot be null.
Parameter name: selectList
Use the "new" keyword to create an object instance
I don't know how to solve this. Could someone, please, help me out?
On my controller I have:
public ActionResult Create() {
SlideViewData viewData = new SlideViewData();
viewData.Targets = Asset.Targets();
viewData.SlidePaper.Slide.Target = "_blank";
return View("Create", viewData);
}
I am testing this on my Create view but as you can see I am defining
Targets and Target.
Asset.Targets is:
public static SelectList Targets() {
var targets = new Dictionary<string, string>();
targets.Add("Blank", "_blank");
targets.Add("Parent", "_parent");
targets.Add("Self", "_self");
targets.Add("Top", "_top");
var list = new SelectList(targets, "Value", "Key");
return list;
}
Thank You,
Miguel