I am working in MVC 1.0. I am using "Telerik Extensions for ASP.NET MVC Q2 2010". I want to use hiperlink in template column.
I take this code for template column from "Extensions for ASP.NET MVC Q2 2010 Documentation" chm,
But after adding template column this page is throwing error and I am not able to understand error point. Please help me in this.
Regards
Atul Kumar Srivastav
<%= Html.Telerik().Grid<Hotel>()
.Name("Hotels")
.BindTo((IEnumerable<Hotel>)ViewData["Hotels"])
.Columns(columns =>
{
columns.Bound(o => o.Name).Title("Hotel");
columns.Bound(o => o.Port).Title("Port");
columns.Bound(o => o.ContactListString).Title("Contacts");
columns.Bound(o => o.FaxNumber).Title("Fax number for voucher");
columns.Template(o =>
{
%>
<%= Html.ActionLink("Edit", "Home", new { id = o.Name }) %>
<%
})
})
.Pageable()
.Sortable()
%>
8 Answers, 1 is accepted
This is the recommended approach of adding a template column and is supposed to work. You forgot to mention what the exception was. I suggest you attach a sample project.
Regards,Atanas Korchev
the Telerik team
I have attached my test application. In this project on "\MovieApp\MovieApp\Views\Home\Index.aspx" I have put my code for template column which have same problem. Please let me know where I am wrong.
Regards
Atul Kumar Srivastav
The problem is that you must use the Render() method when working with server templates:
Also instead of <%= you must use <%. All the best,
Atanas Korchev
the Telerik team
Thanks your previous mail work and I am able to get ahead. but now I got problem with grid Edit command column.
I have again added it in my test application. Please help me again
Regards
Atul Kumar Srivastav
<% Html.Telerik().Grid(Model)
.Name("MovieSet")
.Pageable()
.Sortable()
.DataKeys(keys => keys.Add(c => c.Id))
.ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" }))
.DataBinding(dataBinding => dataBinding.Server()
.Select("EditingServerSide", "Grid", new { mode = GridEditMode.PopUp, type = GridButtonType.Text })
.Insert("Insert", "Grid", new { mode = GridEditMode.PopUp, type = GridButtonType.Text })
.Update("Save", "Grid", new { mode = GridEditMode.PopUp, type = GridButtonType.Text })
)
.Columns(columns =>
{
columns.Bound(o => o.Id).Title("ID");
columns.Bound(o => o.Title).Title("Title");
columns.Bound(o => o.Director).Title("Director");
columns.Bound(o => o.DateReleased).Title("Date Released");
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.ImageAndText);
}).Width(180).Title("Commands");
//Template column which shows an action link
columns.Template(o =>
{
%>
<%= Html.ActionLink("Edit", "Home", new { id = o.Id })%>
<%
}).Title("Edit");
})
.Render();
%>
Unfortunately, as stated here, editing functionality is not available for ASP.NET MVC 1.
Rosen
the Telerik team
I updated my project in mvc2 and now I am using "Telerik Extensions for ASP.NET MVC Q3 2010" dll for my project.
Now I want server side edit on /home/index.aspx my aspx code is this
<% Html.Telerik().Grid(Model)
.Name("MovieSet")
.Pageable()
.Sortable()
.DataKeys(keys => keys.Add(c => c.Id))
.ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" }))
.DataBinding(dataBinding => dataBinding.Server()
.Select("EditingServerSide", "Home", new { mode = GridEditMode.PopUp, type = GridButtonType.Text })
.Insert("Insert", "Home", new { mode = GridEditMode.PopUp, type = GridButtonType.Text })
.Update("Save", "Home", new { mode = GridEditMode.PopUp, type = GridButtonType.Text })
.Update("Delete", "Home", new { mode = GridEditMode.PopUp, type = GridButtonType.Text })
)
.Columns(columns =>
{
columns.Bound(o => o.Id).Title("ID");
columns.Bound(o => o.Title).Title("Title");
columns.Bound(o => o.Director).Title("Director");
columns.Bound(o => o.DateReleased).Title("Date Released");
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.ImageAndText);
}).Width(180).Title("Commands");
})
.Render();
%>
and for I have added this code in HomeController
public ActionResult EditingServerSide()
{
return View(_db.MovieSet.ToList());
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingServerSide(int i)
{
return View(_db.MovieSet.ToList());
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Save(int id)
{
return View(_db.MovieSet.ToList());
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Insert(int id)
{
return View(_db.MovieSet.ToList());
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Delete(int id)
{
return View(_db.MovieSet.ToList());
}
But while I was clicking on edit button this code is throwing error.
The view 'EditingServerSide' or its master was not found. The following
locations were
searched:
~/Views/Home/EditingServerSide.aspx
~/Views/Home/EditingServerSide.ascx
~/Views/Shared/EditingServerSide.aspx
~/Views/Shared/EditingServerSide.ascx
Please help me to solve this. I am attaching my test project for this
Regards
Atul Kumar Srivastav
The error your getting is due to the fact that when no View name is specified when using the Controller's View method, the View which will be loaded by MVC framework is with the name of the action itself. Therefore, in your case a call to EditingServerSide action will result in executing an EditingServerSide View which dies not exists. In order to correct the behavior you should use the overload of the VIew method which explicitly states the View name.
public
ActionResult EditingServerSide()
{
return
View(
"Index"
, _db.MovieSet.ToList());
}
Rosen
the Telerik team
Here is the column code. I just need to clear the filter.
c.Bound(o => o.ACCT_NM)
.ClientTemplate(
"<a href='../Account/LogOn' type='text/plain'><#= ACCT_NUM #></a>")
.Template(o =>
{
%>
<%
= Html.ActionLink(o.ACCT_NUM, "LogOn", "Account") %>
<%
}).Title(
"Acct Num 2").Filterable(true);