0
我想根據MVC中的模型設置下拉顏色。在MVC中設置顏色DropDownListFor
public class Viewer
{
public List<SLI> ls { get; set; }
public string SelectedReport { get; set; }
//public IEnumerable<SelectListItem> MyReports { get; set; }
public string PDFLoc { get; set; }
public List<Status> Stat { get; set; }
}
public class SLI : SelectListItem
{
public string Color { get; set; }
}
我可以設置「顏色」並將其傳遞給視圖。但我不知道如何創建具有款式顏色的新DropDownListFor:紅
我已經試過像各種各樣的事情:
@Html.DropDownListFor(m => m.SelectedReport, new SelectList(Model.ls, "Value", "Text"), new {style = "color: "+ m=>m.ls.Color +"});
,並在控制器:
public ActionResult Viewer()
{
ViewBag.Message = "Your application description page.";
if (S.UserAuthorized())
{
Data D = new Data();
Viewer V= new Viewer();
V.ls = D.GetReportsAssignedToUser();
V.PDFLoc = "";
V.SelectedReport = "";
//Get status of reports
V.Stat = D.GetReportStatuses(V.ls);
return View(V);
}
return RedirectToAction("Index");
}
我真的不獲取匿名方法。 。 。
@SDanks讓我知道如果它的工作原理 – Usman