好吧,我需要一些帮助。我已经回顾了一些与我的问题相关的其他答案,但没有解决。
我正在尝试将操作图像添加到Telerik MVC客户端模板中的网格行。
我遇到的问题是我无法从客户端模板所用的列中获取ID。
这是我的网格:
@(Html.Telerik().Grid<xxx.Business.Entities.EntityName>()
.Name("StudentSearchResults")
.Columns(columns =>
{
columns.Bound(o => o.SchoolStudentID);
columns.Bound(o => o.FirstName);
columns.Bound(o => o.LastName);
columns.Bound(o => o.StudentID).ClientTemplate(
@Html.ActionImage("SubmitDegree", new { studentID = "<#= StudentID #=>" }, "~/Content/Images/Icons/16/bullet_go.png", "Submit Degree").ToString()
).Title("")
.Width(20);
})
.DataBinding(databinding => databinding
.Ajax()
.OperationMode(GridOperationMode.Client)
.Select("AjaxBindAction", "ControllerName"))
.Pageable()
.Sortable()
)
我正在使用HtmlHelperExtension来构造ActionImage:
public static MvcHtmlString ActionImage(this HtmlHelper html, string action, object routeValues, string imagePath, string alt)
{
var url = new UrlHelper(html.ViewContext.RequestContext);
// build the <img> tag
var imgBuilder = new TagBuilder("img");
imgBuilder.MergeAttribute("src", url.Content(imagePath));
imgBuilder.MergeAttribute("alt", alt);
string imgHtml = imgBuilder.ToString(TagRenderMode.SelfClosing);
// build the <a> tag
var anchorBuilder = new TagBuilder("a");
anchorBuilder.MergeAttribute("href", url.Action(action, routeValues));
anchorBuilder.InnerHtml = imgHtml; // include the <img> tag inside
string anchorHtml = anchorBuilder.ToString(TagRenderMode.Normal);
return MvcHtmlString.Create(anchorHtml);
}
我还尝试设置服务器端模板,然后设置客户端模板..发布here
@(Html.Telerik().Grid<AIPortal.Business.Entities.EntityName>()
.Name("StudentSearchResults")
.Columns(columns =>
{
columns.Bound(o => o.SchoolStudentID);
columns.Bound(o => o.FirstName);
columns.Bound(o => o.LastName);
columns.Bound(o => o.StudentID).Template(t => {
@Html.ActionImage("SubmitDegree", new { studentID = t.StudentID }, "~/Content/Images/Icons/16/bullet_go.png", "Submit Degree");
})
.ClientTemplate(
@Html.ActionImage("SubmitDegree", new { studentID = "<#= EntityName.StudentID #>" }, "~/Content/Images/Icons/16/bullet_go.png", "Submit Degree").ToString())
.Title("")
.Width(20);
})
.DataBinding(databinding => databinding
.Ajax()
.OperationMode(GridOperationMode.Client)
.Select("AjaxBindAction", "DegreeCompletion"))
.Pageable()
.Sortable()
)
认为客户端模板中服务器上运行的@ Html.ActionImage可能存在问题?
我能够对StudentID进行硬编码,一切正常。唯一的问题是尝试访问客户端模板所针对的StudentID时。
有人可以指出我正确的方向将此ID输入我的客户端模板吗?
谢谢!
答案 0 :(得分:0)
这是我提出的解决方案..无法在客户端模板中使用@ Html.ActionImage方法。
@(Html.Telerik().Grid<xxx.Business.Entities.EntityName>()
.Name("StudentSearchResults")
.Columns(columns =>
{
columns.Bound(o => o.SchoolStudentID);
columns.Bound(o => o.FirstName);
columns.Bound(o => o.LastName);
columns.Bound(o => o.StudentID).ClientTemplate(
"<a href=\"/DegreeCompletion/SubmitDegree?studentID=<#= StudentID #>\"><img alt=\"Submit Degree\" src=\"/Content/Images/Icons/16/bullet_go.png\"></a>")
.Title("")
.Width(20);
})
.DataBinding(databinding => databinding
.Ajax()
.OperationMode(GridOperationMode.Client)
.Select("AjaxBindMethod", "DegreeCompletion"))
.Pageable()
.Sortable()
)