I am using the telerik mvc grid to save the data with inform editing.
I have a situation like i want the user to redirect to login page after inserting some data.
In my case i am able to call the Action Method in Controller but the View is not rendered.
Any help will be appreciated.
8 Answers, 1 is accepted
We need some additional information. Please paste here the declaration of your grid and the action method.
All the best,Atanas Korchev
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
Thanks for the reply. Below is the information that you asked
The Grid Declaration is
<%=Html.Telerik().Grid(Model)
.Name("Grid")
.DataKeys(keys => keys.Add(o => o.Id).RouteKey("Id"))
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("Select", "Home")
.Update("Update", "Home")
.Delete("Delete", "Home")
.Insert("Insert", "Home")
.Columns(columns =>
{
columns.Bound(c => c.FirstName);
columns.Bound(c => c.LastName);
columns.Bound(c => c.UserName);
columns.Bound(c => c.Password);
columns.Bound(c => c.Telephone);
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.Image).HtmlAttributes(new {Style = "float : top"});
commands.Delete().ButtonType(GridButtonType.Image);
}
);
})
.Editable(editing =>editing.Mode(GridEditMode.InForm))
.ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Image))
.Pageable()
%>
In insert action method i am writing code like below
public ActionResult Insert(Model model)
{
SaveDetails(model);
return RedirectToAction("LogOff", "Security", new {area = "Public", logonType = LogonType.Guest.ToString()});
}
Let me know if you need any more help.
As you may know request cannot be redirected during ajax request. Therefore, in order to achieve this you should redirect to the destination page after the request has been received by the browser.
This in your scenario can be accomplished by using Error event of the grid and sending a special value from the server. For example:
<%=Html.Telerik().Grid(Model).Name(
"Grid"
)
.ClientEvents(events => events.OnError(
"error"
))
//....
%>
public
ActionResult Insert(Model model)
{
SaveDetails(model);
return
Content(
"redirect="
+ Url.Action(
"LogOff"
,
"Security"
,
new
{area =
"Public"
, logonType = LogonType.Guest.ToString()}));
}
<script type=
"text/javascript"
>
function
error(e) {
var
text = e.XMLHttpRequest.responseText,
name =
"redirect="
,
start = text.indexOf(name);
if
(start > -1) {
location.href = text.substring(start + name.length);
e.preventDefault();
}
}
</script>
Regards,
Rosen
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
I had done the changes as suggested by you
but i an getting javascript error as mentioned below at the time of load of telerik grid.
"Microsoft JScript runtime error: 'error' is undefined"
public ActionResult Insert(Model model)
{
if(!LogonType.Guest)
{
SaveDetails(model);
return(new GridModel(GetData());
}
else
{
SaveDetails(model);
return RedirectToAction("LogOff", "Security", new {area = "Public", logonType = LogonType.Guest.ToString()});
}
}
Could you please verify that you have attached the error event correctly and a function with such name exists.
Regards,Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Here is my code telerik grid that i have written let me know if it is correct
<%=Html.Telerik().Grid(Model)
.Name("Grid")
.DataKeys(keys => keys.Add(o => o.Id).RouteKey("Id"))
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("Select", "Home")
.Update("Update", "Home")
.Delete("Delete", "Home")
.Insert("Insert", "Home")
.Columns(columns =>
{
columns.Bound(c => c.FirstName);
columns.Bound(c => c.LastName);
columns.Bound(c => c.UserName);
columns.Bound(c => c.Password);
columns.Bound(c => c.Telephone);
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.Image).HtmlAttributes(new {Style = "float : top"});
commands.Delete().ButtonType(GridButtonType.Image);
}
);
})
.ClientEvents(events => events.OnError("error"))
.Editable(editing =>editing.Mode(GridEditMode.InForm))
.ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Image))
.Pageable()
%>
<
script type="text/javascript">
function error(e) {debugger;
var text = e.XMLHttpRequest.responseText,
name =
"redirect=",
start = text.indexOf(name);
if (start > -1) {
location.href = text.substring(start + name.length);
e.preventDefault();
}
}
</
script>
Let me Know if if i had missed any thing in the code or if there is something wrong in the code.
Thanks
Robin
The issue has been resolved.
I need to change the handler name to something else instead of name.
I don't know why it is so. but thanks for all your help