webgrid

If else in Web Grid Column

喜夏-厌秋 提交于 2019-12-10 15:08:05
问题 How to put a condition (if else) in webgrid column? @grid.GetHtml(tableStyle: "table table-bordered", columns: grid.Columns( grid.Column("RealName", "Name"), grid.Column("UserName", "Email") )) I have to show the Email Column based on a condition, How to do this? 回答1: You can try this @{ var gridColumns = new List<WebGridColumn>(); gridColumns.Add(grid.Column(format: (item) => Html.ActionLink("Select", "Details"))); if (true) { gridColumns.Add(grid.Column(format: (item) => Html.ActionLink(

Why can't I use my extension method in a delegate in the Razor WebGrid

南笙酒味 提交于 2019-12-10 13:52:45
问题 I'm using the MVC 3 introduced WebGrid, but can't can't apply my own extension methods when passing a delegate for the format param. Using: Grid.Column("MyProperty", "MyProperty", format: @<span class="something">@item.MyProperty.MyExtensionMethodForString()</span>) I got ERROR: 'string' does not contain a definition for 'MyExtensionMethodForString' I've tried casting, not to avail Grid.Column("MyProperty", "MyProperty", format: @<span class="something">@((string)(item.MyProperty)

add row in webgrid

故事扮演 提交于 2019-12-10 10:15:44
问题 I'm working with MVC 3 webgrid and i need to add a new row into webgrid to show sum of price from product table. Any ideas are appreciated. Here's my code @{ WebGrid grid = new WebGrid(source: Model, rowsPerPage: 3, canSort: true, canPage: true, ajaxUpdateContainerId: "ajaxgrid"); @grid.GetHtml( alternatingRowStyle: "altrow", mode: WebGridPagerModes.All, firstText: "<< ", previousText: "< ", nextText: " >", lastText: " >>", columns: grid.Columns( grid.Column(format: (item) => new HtmlString

How can I hide a WebGrid column based on the current user's role?

早过忘川 提交于 2019-12-10 10:02:22
问题 I need to do a grid using webgrid and I would like to hide the column (header and items) of edit actions based on user role. How can I do that with webgrid? 回答1: You could write a helper method which would generate the columns dynamically based on user roles: public static class GridExtensions { public static WebGridColumn[] RoleBasedColumns( this HtmlHelper htmlHelper, WebGrid grid ) { var user = htmlHelper.ViewContext.HttpContext.User; var columns = new List<WebGridColumn>(); // The Prop1

How to cache mvc3 webgrid results (so that col sort click doesn't?

99封情书 提交于 2019-12-09 03:23:14
问题 Can somebody please tell me how I can cache my webgrid results so that when I sort by column it doesn't re-run my stored procedure query every time? When clicking on a column link to sort, the stored proc (which is a little slow) that populates the table/grid is re-executed every time and hits the database. Any caching tips and tricks would be greatly appreciated. Thx! 回答1: Well inside the controller action which is invoking the method on your repository supposed to query the database you

Fetch all the value from database to webgrid of ASP MVC ASPX

瘦欲@ 提交于 2019-12-08 13:57:32
问题 Hi I am getting only the last value from the database in the webgrid. I have used foreach to get all the value from the database and binded it to the webgrid but it is showing only the last value in the webgrid . Please guide me var listobject = list ; foreach (var m in ViewBag.Model) { var list = new[] { new { Name = m.Name, Genre =m.Genre } }; listobject = list; } WebGrid studentGrid = new WebGrid(); studentGrid.Bind(listobject, autoSortAndPage: false, rowCount: 3); %> <%= studentGrid

htmlhelper inside webgrid

↘锁芯ラ 提交于 2019-12-08 07:49:03
问题 I'm using MVC3 and I need a HTMLHelper with image, so I found a nice code, the problem is that the image is not shown instead of I see html code ex: <a href='whatever'><img src="images/printer.png" /></a> Maybe this is because the helper is inside a webgrid helper, I really don't know, any suggestion? Helper <Extension()> _ Public Function ActionLinkWithImage(ByVal helper As HtmlHelper, ByVal actionName As String, ByVal controllerName As String, ByVal imageUrl As String, ByVal alternateText

checkbox oncheck redirect to actionresult in mvc

◇◆丶佛笑我妖孽 提交于 2019-12-08 04:00:30
I am creating a project in mvc which uses webgrid. In the webgrid I have two columns namely Status and IsActive . The status column can contain only two values: checked or unchecked .Both these values come from database. The IsActive column has checkbox which is in checked state if the status is checked in the Status column and vice versa. I have an actionresult in my controller which checks the status of the particular row and reverses it (i.e) If the status was checked it will change to unchecked and vice versa.This is the code: public ActionResult Add(string path,string status) { on.Open();

MVC3 WebGrid Page/Sort Issue with a CheckBox elsewhere on the page

雨燕双飞 提交于 2019-12-07 15:37:58
问题 I have a checkbox on my page, created as such: @Html.CheckBoxFor(x => x.MyBoolValue) Beneath that I have a WebGrid with sorting and paging, but on doing this I get a System.InvalidOperationException: The parameter conversion from type 'System.String' to type 'System.Boolean' failed. See the inner exception for more information. The inner exception is: {"true,false is not a valid value for Boolean."} I know this is due to the binding of the CheckBox and the underlying Hidden value. On a page

How to add Html inside ASP.NET MVC 3 WebGrid Column Name (Header)

怎甘沉沦 提交于 2019-12-07 15:32:56
问题 I am unable to add html inside WebGrid column name(at header)? When I add html inside column name then webgrid encodes that. Is this is not possible to add html inside WebGrid column name? 回答1: There is a method to change html generated by an MVC Helper, but it's not very comfortable. In general you can write this command: @( new HtmlString( Component.HelperMethod().ToHtmlString().Replace("[replacetag]", "My Content")) ) Here is an example using a grid component: <div id="grid"> @(new