This is a migrated thread and some comments may be shown as answers.

Add data to a dropdownlist in a editor template

2 Answers 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mattias
Top achievements
Rank 1
Mattias asked on 09 Dec 2010, 01:46 PM
Hi,
I have read a couple of threads here about dropdownlists and editor templates but I didn't find what I'm looking for!
Currently I have this editor template:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<%= Html.DropDownList("", (SelectList)ViewData["ClientListItems"]) %>

 And I add the data in my controllers index method:
...
ViewData["ClientListItems"] = new SelectList(_resourceService.GetAllClients(), "ID", "ClientName");
 
var model = new ResourceDisplayViewModel();
model.BindDomainModel( _resourceService.GetAllResources());
 
return View(model);

This works fine but I wonder now, is there any option for using the ViewData property?
It would be cleaner if I could add the selectlist to my viewmodel instead, like:
var model = new ResourceDisplayViewModel();
model.BindDomainModel( _resourceService.GetAllResources());
model.ClientSelectList = new SelectList(_resourceService.GetAllClients(), "ID", "ClientName");
 
return View(model);

Is that possible? If yes, how do I transfer the select list to my editor template in the grid?
If it's not possible, are there any other way to bind the editor template?

Regards,
Mattias

2 Answers, 1 is accepted

Sort by
0
Troy
Top achievements
Rank 1
answered on 17 Aug 2011, 06:01 PM
Mattias,

Did you ever work this out? I am currently having the exact same issue and have been hitting my head against this for way too long now. I've been browsing threads, asking questions, and yet haven't been able to figure out how to do this. So, if you did work it out, and wouldn't mind sharing, that would be awesome.

Thank you!
0
Mattias
Top achievements
Rank 1
answered on 18 Aug 2011, 06:58 AM
Hi Troy,
Sorry but no, I haven't looked any more on this issue but I'm pretty sure that there is a way!

/Mattias
Tags
Grid
Asked by
Mattias
Top achievements
Rank 1
Answers by
Troy
Top achievements
Rank 1
Mattias
Top achievements
Rank 1
Share this question
or