webgrid

Add custom attributes to table rendered by WebGrid

时光怂恿深爱的人放手 提交于 2019-12-02 02:49:11
I am using an MVC3 WebGrid, and want to add custom attributes of the form "data-xxx" to the <table> element rendered by WebGrid.GetHtml() . I tried to do this as follows: grid.GetHtml(... htmlAttributes: new { data_xxx = "value" } ); However this renders as: <table ... data_xxx="value"> instead of the expected: <table ... data-xxx="value"> I.e. unlike other MVC helpers, it doesn't replace the underscore in the property name with a hyphen. After a bit of spelunking with Reflector it seems that: WebGrid.GetHtml() calls System.Web.WebPages.Html.ObjectToDictionary to convert the anonymous

post items of webgrid asp.net mvc3

感情迁移 提交于 2019-11-30 22:58:45
I have these DTO's public class Header { public int HeaderId{get;set;} public int Description{get;set;} public List<HeaderItem> HeaderItems{get;set;} } public class HeaderItem { public int HeaderItemId{get;set;} public string DetailDescription{ get; set; } public bool Selected{ get; set; } } and I have this Controller [HttpPost] public ActionResult PostMethod(Header dto) { ... } and this html @using (Html.BeginForm("PostMethod", "Controller", FormMethod.Post, new { id = "form" })) { @Html.TextBoxFor(x => x.Description) var grid = new WebGrid(Model.HeaderItems); } @grid.GetHtml(tableStyle:

Populate MVC Webgrid from DataTable

▼魔方 西西 提交于 2019-11-30 21:56:13
I am trying to populate a MVC Webgrid using a DataTable which is built up in the code behind and then made enumerable using the AsEnumerable() extension method. However, when I call the GetHtml method, the output is not what I expect, it consists of two columns HasErrors and RowError and none of the columns I have defined. Am I missing something? DataTable table = new DataTable(); table.Columns.Add("I/Dia"); foreach (var item in Variations.Where(item => !table.Columns.Contains(item.CrossSectionalDiameter))) { table.Columns.Add(item.CrossSectionalDiameter); } foreach (var item in Variations) {

Populate MVC Webgrid from DataTable

。_饼干妹妹 提交于 2019-11-30 17:11:43
问题 I am trying to populate a MVC Webgrid using a DataTable which is built up in the code behind and then made enumerable using the AsEnumerable() extension method. However, when I call the GetHtml method, the output is not what I expect, it consists of two columns HasErrors and RowError and none of the columns I have defined. Am I missing something? DataTable table = new DataTable(); table.Columns.Add("I/Dia"); foreach (var item in Variations.Where(item => !table.Columns.Contains(item

MVC3 WebGrid Custom Text in Column

拜拜、爱过 提交于 2019-11-30 13:32:13
I'm developing a web application using MVC3 in VB.NET. I having difficulty setting a column on the webgrid with the following action links Edit | Details | Delete @*@Html.ActionLink("Edit", "Edit", New With {.id = currentItem.PrimaryKey}) | @Html.ActionLink("Details", "Details", New With {.id = currentItem.PrimaryKey}) | @Html.ActionLink("Delete", "Delete", New With {.id = currentItem.PrimaryKey})*@ I have tried to use syntax below but I get an error where item is not declared. grid.Column(header:= "",format:= (item) => item.GetSelectLink("Custom Text")) How do I reference the current row or

MVC 3 Webgrid make entire row clickable

≯℡__Kan透↙ 提交于 2019-11-30 05:03:07
问题 I am using webgrid in my razor view in MVC 3. Below is how my webGrid looks, I want to make the entire row clickable and on click pass values to the javascript method also. I am able to achieve calling my javascript method on text of all columns. I want the same to happen for click of anywhere on the entire row. Please guide me on this. Thanks @grid.GetHtml( columns: grid.Columns( grid.Column("CompanyName", format: @<text><a href="javascript:SubmitValues('@item.Col1','@item.Col2','@item.Col3'

MVC3 WebGrid Custom Text in Column

我是研究僧i 提交于 2019-11-29 19:06:51
问题 I'm developing a web application using MVC3 in VB.NET. I having difficulty setting a column on the webgrid with the following action links Edit | Details | Delete @*@Html.ActionLink("Edit", "Edit", New With {.id = currentItem.PrimaryKey}) | @Html.ActionLink("Details", "Details", New With {.id = currentItem.PrimaryKey}) | @Html.ActionLink("Delete", "Delete", New With {.id = currentItem.PrimaryKey})*@ I have tried to use syntax below but I get an error where item is not declared. grid.Column

ASP.NET MVC3 WebGrid - custom, server-side sorting

空扰寡人 提交于 2019-11-29 14:42:33
Is there a way to override default MVC3 WebGrid sorting behavior to call my controller (which will perform server side sorting and return the data) when sort is called? Thanks for any help! You can pass the server side sorted data to the webgrid, along with the info on how many records there are. http://msdn.microsoft.com/en-us/magazine/hh288075.aspx has a helpful walkthrough. I'm doing database level sorting/filtering/paging to minimize the amount of data being passed around. I don't think my webserver would love me if I passed all 70,000 objects a customer has just so they can see the 25 on

Conditionally display an image in webgrid - mvc 3

空扰寡人 提交于 2019-11-28 23:44:37
In my webgrid I need to display images based on the value .. Code is given below @model TraktorumMVC.Models.ManagePhotos @{ ViewBag.Title = "ManagePhotos"; Layout = "~/Views/Shared/_Layout.cshtml"; var grid = new WebGrid(Model.AdPhotos); } @grid.GetHtml( displayHeader: false, columns: grid.Columns( grid.Column(format: (item) => { if (item.IsMainPreview == true) { return @<text><img src="@Url.Content("~/Content/images/preview-photo.gif")" alt="Image "/></text>; } else { return @<text><img src="@Url.Content("~/Content/images/non-preview-photo.gif")" alt="Image "/></text>; } } ), grid.Column

Using data in a HTML.ActionLink inside a WebGrid.column, not possible?

∥☆過路亽.° 提交于 2019-11-28 06:53:31
I have the following WebGrid in my ASP.NET MVC3 test application. It displays a list of customers: @grid.GetHtml( tableStyle: "grid", headerStyle: "head", alternatingRowStyle: "alt", columns: grid.Columns ( grid.Column(format: (item) => Html.ActionLink("Edit", "Details", new { id = item.id })), grid.Column("Address.CompanyName"), grid.Column("Address.City") ) ) The interesting part here is the Edit-link I've added in the first column. I would like to use the customers account number instead of the plain "Edit"-test. However, it causes me a great deal of problems to do so. I've tried: grid