Click here to Skip to main content
15,883,647 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear friends

i have got the func<dynmic,object> error where the Model._user.select(d=>d.UserRole) in dropdownlist when binding the dropdown value in Webgrid

my coding s

Model:

public string UserLastName { get; set; }
public string UserEmail { get; set; }
public string UserRole { get; set; }

public class UserAccount
{
public IEnumerable<users> _User { get; set; }
public IEnumerable<SelectListItem> UserRoles { get; set; }

}

Controller:

public ActionResult Users()
{

var Data = _objUserRespository.GetUser();
var Model = new UserAccount();
{
Model._User = Data;
Model.UserRoles = new[]{
new SelectListItem{Text = "Admin",Value="Admin"},
new SelectListItem{Text = "Trader",Value="Trader"}
};
}
return View(Model);

View:

@model dataanalysys.Models.UserAccount

var grid = new webgrid(model._user)

@grid.gethtml(

columns:grid.columns(

grid.column("userlastanem"),

grid.column("useremail"),

grid.Column("UserRole", "User Role", format: @<text>
<label id="lblusrrole">
@item.UserRole
</label>



@Html.DropDownList("UserRole",Model._user.select(d=>d.UserRole),Model.UserRoles,new { id = "UserRole", @class = "edit-mode" })

)

how to solve this error , can anyone help me.
Posted
Updated 17-Jun-13 0:47am
v2
Comments
Jameel VM 17-Jun-13 3:09am    
What error you got?
sumathisumi 17-Jun-13 6:47am    
i just got an error where Model._user.select(d=>d.UserRole) in htnl.dropdownlist
Jameel VM 17-Jun-13 10:35am    
can you post the complete @html.Dropdownlist code?
sumathisumi 18-Jun-13 0:43am    
@Html.DropDownList("UserRole",Model._user.select(d=>d.UserRole),Model.UserRoles,new { id = "UserRole", @class = "edit-mode" })

this is my complete dropdown code

update your class with this classes in Model

public class UserDetail
{
public string UserLastName { get; set; }
public string UserEmail { get; set; }
public string UserRole { get; set; }
}
public class UserAccount
{
public IEnumerable<userdetail> _User { get; set; }
public IEnumerable<selectlistitem> UserRoles { get; set; }

}

cshtml file (view)
@model CodeProject.Models.UserAccount

@{
ViewBag.Title = "Users";
}

Users


@{
var grid = new WebGrid(Model._User, canPage: true, rowsPerPage: 5, selectionFieldName: "selectedRow", ajaxUpdateContainerId: "gridContent");
grid.Pager(WebGridPagerModes.NextPrevious);


@grid.GetHtml(tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: grid.Columns(
grid.Column("UserLastName", " Last Name"),
grid.Column("UserEmail", "Email Id", style: "description"),
grid.Column("UserRole", "UserRole"),
grid.Column("UserRoles", format: @item => Html.DropDownListFor(m => Model.UserRoles, Model.UserRoles, new { style = "width: 150px; background-color:gray" }))


))

}

Shahid Husain
SSE
 
Share this answer
 
Hi,

You can use as following..

<pre lang="HTML">
@Html.DropDownList("BankId", "Please select", cb_accounts, mBankId, new { @class = "special" })

1) cb_accounts is a selectedlist item as

<pre lang="c#">
var cb_accounts = data.Select(i => new SelectListItem
{
Value = i.AccountId.ToString(),
Text = i.Name
});

2) mBankId holds the default value to select

Hope this will help you.
thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900