2011-10-31 62 views
0

我想将下面的asp dropdowlist转换为telerik mvc dropdownlist。 我正在使用SQL存储过程来弹出列表。MVC下拉列表Telerik MVC Dropdowlist

<asp:DropDownList ID="userName" name="userName" runat="server" DataSourceID="SqlDataSource1" 
     DataTextField="FullName" DataValueField="UserName"> 
    </asp:DropDownList> 
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HHNConnectionString %>" 
     SelectCommand="GetUserName" SelectCommandType="StoredProcedure"></asp:SqlDataSource> 

在此先感谢。

回答

0

combobox是你正在寻找我假设。你在问如何用Telerik控件重写你的控件?那么,首先你不用MVC控件指定存储过程。你会想要通过你的viewmodel。无论您用于数据库连接,将负责调用存储过程。

// Controller method 
public ActionResult MyAction() 
{ 
    // Pull user names from the database 
    var users = _repository.FindAllUsers().Select(u => u.UserName); 
    return View(users); 
} 

那么你的观点会是这个样子:

@model IEnumerable<string> 

@(Html.Telerik().DropDownList() 
    .Name("userName") 
) 

如果你有一个预先选定的用户名,然后你需要创建一个实际的视图模型类:

public MyViewModel 
{ 
    public string UserName { get; set;} 
    public IEnumerable<string> UserList { get; set; } 
} 

然后您可以使用@(Html.Telerik().DropDownListFor(m => m.UserName))方法。

+0

谢谢。这工作。 – hncl