好吧我需要一些幫助。我回顧了一些與我的問題有關的其他答案,但沒有解決它。Telerik MVC Grid Client模板問題
我想將操作圖像添加到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到我的客戶端模板?
謝謝!
我知道我遲到了,但我目前正在努力建立一個可編輯網格。關於客戶端中的Html.ActionImage,我正在嘗試使用RazorEngine來使用Razor語法生成客戶端字符串。 – B2K 2014-09-16 15:11:54