webgrid

add row in webgrid

那年仲夏 提交于 2019-12-06 00:29:33
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(Html.ActionLink("Edit", "Edit", new { id = item.ProductId }).ToString() + " | " + Html.ActionLink(

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

狂风中的少年 提交于 2019-12-05 23:59:26
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? 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 column would be visible to all users columns.Add(grid.Column("Prop1")); if (user.IsInRole("foo")) { // The

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

廉价感情. 提交于 2019-12-05 18:45:45
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? 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 HtmlString( grid.GetHtml( tableStyle: "grid", headerStyle: "header", rowStyle: "row", footerStyle: "footer",

ASP.NET MVC3 WebGrid Helper and Model Metadata

♀尐吖头ヾ 提交于 2019-12-05 17:47:32
I'm trying to use the WebGrid html helper in ASP.NET MVC 3 to autogenerate the columns according to the information found in the ModelMetadata. For example the code in a view that accepts a list of objects would be: var grid = new WebGrid(Model); @grid.GetHtml(columns: ViewData.ModelMetadata.Properties.Single.Properties .Select(p => grid.Column( columnName: p.PropertyName, header: p.ShortDisplayName ))); This actually works like a charm (I was surprised it was that easy actually). What happens here is that from the properties of the model I use the ShortDisplayName as the column's header. The

How to achieve edit and delete on Webgrid of MVC3 Razor?

百般思念 提交于 2019-12-05 03:52:38
问题 Below I have given the controller, model and view. After run, grid is displaying with values, but I need to edit the values and delete the values on same page. I have searched and seen some example, in that for edit, delete they creating separate index but mine need is to edit and delete should done on same page instead of another page. Please give me a solution. Controller: public ActionResult Index() { var PersonList = new List<Person>() { new Person(){Name="A", Age=20,Id =1}, new Person()

Problems with MVC 3 DropDownList() in WebGrid()

断了今生、忘了曾经 提交于 2019-12-04 19:57:33
I'm trying to place a DropDownList inside a WebGrid but I can't figure out how to do it :( Things I've tried: grid.Column("Id", "Value", format: ((item) => Html.DropDownListFor(item.SelectedValue, item.Colors))) and grid.Column(header: "", format: (item => Html.DropDownList("Colors", item.Colors))) and grid.Column(header: "", format: Html.DropDownList("Colors")) and various others but I couldn't get it to work. Any help is much appreciated. Model public class PersonViewModel { public string Name { get; set; } public int Age { get; set; } public SelectList Colors { get; set; } public int

How do I get my WebGrid to POST instead of GET during a sort or paging operation in my MVC4 site?

江枫思渺然 提交于 2019-12-04 17:45:15
I have a fairly simple site with a Search partial view and a Listing partial view. They're rolled up using multiple models into the Index view. Everything is fine. Except when I click the grid column headers to sort or attempt to page to the next listing of data, the grid comes back empty. If I re-submit the same search criteria, then the grid repopulates with all applicable data sorted or paged properly. I've tracked this behavior down to the fact that the WebGrid sets up it's paging and sorting mechanisms as a GET instead of a POST. So obviously all my model data is left off the submission.

MVC WebGrid - How to programatically get the current page, sort column etc

允我心安 提交于 2019-12-04 14:50:47
How can I programatically (in javascript) get the current page number, last sort column and sort direction of the ASP.NET MVC WebGrid? Is it possible to update the arguments before it calls the $("#grid").load() method? The only possible solution was to use jQuery to retrieve: - the "href" attribute from the first column header to get the page number and - the "href" attribute from the "next page number" to get the sort column and sort directions. function reloadGrid(form) { var grid = form._grid ? form._grid.value : "grid"; var args = {}; updateQueryParams(args, grid + " th a"); args.sort = "

Is the MVC WebGrid Open Source?

℡╲_俬逩灬. 提交于 2019-12-04 10:52:40
Is the MVC WebGrid Open Source? If so where can I find the source code. The current version of the WebGrid has little to no documentation, incomplete implemtation etc. I am trying to do a simple thing as adding a visibility property to the WebGrid.Column() in the view, but that is impossible You can download the source code of ASP.NET MVC 3 and inside you have the source of WebGrid. Once you unzip you will find it inside the webpages/src/System.Web.Helpers/WebGrid/WebGrid.cs file. Good luck with modifying it :-) (1104 lines in a single source code file) 来源: https://stackoverflow.com/questions

How to achieve edit and delete on Webgrid of MVC3 Razor?

强颜欢笑 提交于 2019-12-03 21:12:14
Below I have given the controller, model and view. After run, grid is displaying with values, but I need to edit the values and delete the values on same page. I have searched and seen some example, in that for edit, delete they creating separate index but mine need is to edit and delete should done on same page instead of another page. Please give me a solution. Controller: public ActionResult Index() { var PersonList = new List<Person>() { new Person(){Name="A", Age=20,Id =1}, new Person(){Name="B",Age=45,Id =2}, new Person(){Name="C", Age=30,Id =3}, new Person(){Name="D",Age=55,Id =4}, new