Hello,
I need to bring add, update functionalities inside grid and grid contains two drop down list boxes. am able to bring DDL inside grid but when on update or insert its not routing DDL selected item value to controller. my implementation goes like this
Model:
-----------------
public class Admin
{
[DataType(DataType.Text),Required]
[DisplayName("Login ID")]
public string LoginID { get; set; }
[UIHint("Role")]
[DisplayName("User Role")]
public Role Role { get; set; }
[UIHint("Company")]
[DisplayName("Company Name")]
public Company Company { get; set; }
[DisplayName("IsActive")]
public bool IsActive { get; set; }
}
code to populate role:
--------------------
ViewData["role"] = objListRole.Select(e => new { RoleID = e.RoleID, RoleName = e.RoleName });
ViewData["company"] = objListCompany.Select(e=> new {CompanyID = e.CompanyID , CompanyName = e.CompanyName});
MarkUp:
------------
<%= Html.Telerik().Grid(Model)
.Name("Grid")
.DataKeys(keys => keys.Add(c => c.LoginID))
.ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0", title = "Add New User" }))
.DataBinding(dataBinding => dataBinding.Server()
.Select("Selection", "AdminUser")
.Insert("InsertUser", "AdminUser", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
.Update("Save", "AdminUser", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
.Delete("Delete", "AdminUser", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText }))
.Columns(columns =>
{
columns.Bound(c => c.LoginID).Title("Login ID");
columns.Bound(c => c.Role).Title("User Role");
columns.Bound(c => c.Company).Title("Company Name");
columns.Bound(c => c.IsActive).Title("IsActive");
columns.Bound(c => c.LoginID).Title("").Format(Html.ActionLink("Generate Password", "ResetPassword", new { id = "{0}" }).ToHtmlString()).Encoded(false).Width(150).ReadOnly(true);
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.ImageAndText);
commands.Delete().ButtonType(GridButtonType.ImageAndText);
}).HtmlAttributes(new { style = "white-space:nowrap !important;" }).Width(200).Title("");
})
.Editable(editing => editing.Mode(GridEditMode.InLine))
.Selectable()
.Footer(true)
%>
DDL MarkUp: (Similrly for Roles to populate mark up is there in folder display template and edit template)
-------------------
<%= Html.Telerik().DropDownList()
.Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
.BindTo(new SelectList((IEnumerable)ViewData["company"], "CompanyID", "CompanyName", Model == null ? "" : Model.CompanyID.ToString()))
%>
Code Called when click on update button:
public
ActionResult Save(string id,int? roleId,int? comp)
Here roleId and Comp are always null.
Please help. its very urgent.
Thanks in advance,
Ganesh N