[英]Binding KeyFieldName from gridview to Url.Action inside column settings
Im trying to get Objects keyfield value to a RouteValueDictionary inside column settings, However for some reason i can only access the field bound to the column inside this call!我试图在列设置中将对象键域值获取到 RouteValueDictionary,但是由于某种原因,我只能访问绑定到此调用中的列的字段!
Code:代码:
@Html.DevExpress().GridView(settings =>
{
//General settings
settings.Name = "name";
settings.KeyFieldName = "ID";
//Other settings etc.....
settings.Columns.Add(column =>
{
column.Name = "Name";
column.FieldName = "CurrentFieldBoundToColumn";
column.Caption = "Some caption";
//Set hyperlink
column.ColumnType = MVCxGridViewColumnType.HyperLink;
var hyperLinkProperties = column.PropertiesEdit as HyperLinkProperties;
String urlFormatString = Url.Action("Action", "Controller", new RouteValueDictionary(new { ID= "{0}" }));
hyperLinkProperties.NavigateUrlFormatString = HttpUtility.UrlDecode(urlFormatString);
});
//Other Columns etc etc
});
{ ID= "{0}" })) This is where i need the Keyfield value however whatever i try i only get the value bound to the column column.FieldName = "CurrentFieldBoundToColumn". { ID= "{0}" })) 这是我需要 Keyfield 值的地方,但是无论我尝试什么,我都只会得到绑定到列 column.FieldName = "CurrentFieldBoundToColumn" 的值。 Anny ideas?有什么想法吗?
EDIT;编辑;
Got it woorking like so :得到它像这样工作:
settings.Columns.Add(column =>
{
column.Name = "Name";
column.FieldName = "CurrentFieldBoundToColumn"";
column.Caption = "SomeCaption";
//Set hyperlink
column.SetDataItemTemplateContent(content =>
ViewContext.Writer.Write
(
Html.ActionLink
(
linkText: content.Text,
actionName: "Action",
controllerName: "Controller",
routeValues: new { ID = content.KeyValue },
htmlAttributes: null
)
));
});
You can use SetDataItemTemplateContent method with a simple ActionLink and GridViewBaseRowTemplateContainer.KeyValue property:您可以将SetDataItemTemplateContent方法与简单的ActionLink和GridViewBaseRowTemplateContainer.KeyValue属性一起使用:
@Html.DevExpress().GridView(settings =>
{
//General settings
settings.Name = "name";
settings.KeyFieldName = "ID";
//Other settings etc.....
settings.Columns.Add(column =>
{
column.Name = "Name";
column.FieldName = "CurrentFieldBoundToColumn";
column.Caption = "Some caption";
column.SetDataItemTemplateContent(content =>
ViewContext.Writer.Write(
Html.ActionLink(content.Text, "Action", "Controller",
new { ID = content.KeyValue }, null)));
});
//Other Columns etc etc
});
settings.Columns.Add(c =>
{
c.FieldName = "Dept_Name"; c.Caption = "Dept Name";
c.SetDataItemTemplateContent(i =>
{
ViewContext.Writer.Write(Html.ActionLink(DataBinder.Eval(i.DataItem, "Dept_Name").ToString(), "Edit", new { Dept_Id = DataBinder.Eval(i.DataItem, "Dept_Id").ToString().Trim() }).ToHtmlString());
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.