I am working on asp.net core application and using nonfactors webgrid.
In some scenario I need to create different html tag for true
and false
value of model property.
For true
=> any div
tag
For false
=> any image
tag
Anybody have any idea regarding this?
I use the NonFactors MVC Grid frequently, I'm a little confused on your question but I'll answer what I think I read.
Each field can be rendered however you see fit.. when a field is true you could render a div tag with whatever in it, when false an image tag with something else. Here is an example using that grid (I am using a User model as the example.. so that Model.Users is an IEnumerable of that model):
@(Html
.Grid(Model.Users)
.Build(columns =>
{
columns.Add(model => model.username).Titled("Username");
columns.Add(model => model.first_name).Titled("First Name");
columns.Add(model => model.last_name).Titled("Last Name");
columns.Add(model => model.last_login).Titled("Last Login").RenderedAs(model => model.last_login == DateTime.MinValue ? "Never" : model.last_login.ToString());
columns.Add(model => model.banned).Titled("Banned").Encoded(false).RenderedAs(model => model.banned ? "<div>whatever goes here</div>" : "<img />");
})
.Filterable()
.Sortable()
.Pageable()
.Css("table table-sm table-striped table-hover table-responsive")
)
您需要熟悉控制结构 。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.