This is a migrated thread and some comments may be shown as answers.
Query Regarding Redirecting View after Insert
8 Answers 39 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ambrish
Top achievements
Rank 1
Ambrish asked on 19 Jul 2011, 10:49 AM
Hi All,

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

Sort by
0
Atanas Korchev
Telerik team
answered on 19 Jul 2011, 11:40 AM
Hello Ambrish,

 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!

0
Ambrish
Top achievements
Rank 1
answered on 25 Jul 2011, 11:29 AM
Hi Atanas Korchev,

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.
0
Accepted
Rosen
Telerik team
answered on 26 Jul 2011, 09:01 AM
Hi Ambrish,

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!

0
Ambrish
Top achievements
Rank 1
answered on 26 Jul 2011, 01:21 PM
Hi Rosen,

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"
0
Ambrish
Top achievements
Rank 1
answered on 26 Jul 2011, 01:39 PM
My action method is like

 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()});
                }
         }

0
Rosen
Telerik team
answered on 26 Jul 2011, 04:14 PM
Hello Ambrish,

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

0
Ambrish
Top achievements
Rank 1
answered on 27 Jul 2011, 06:28 AM
Hi Rosen,
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

 

 

 

0
Ambrish
Top achievements
Rank 1
answered on 27 Jul 2011, 07:49 AM
Hi All,

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
Tags
Grid
Asked by
Ambrish
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Ambrish
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or