This question is locked. New answers and comments are not allowed.
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:
And I add the data in my controllers index method:
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:
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
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