This is a migrated thread and some comments may be shown as answers.

How can I select a record in a Grid and then post that record to an action (and View) in another controller?

4 Answers 89 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Arnold Smith
Top achievements
Rank 1
Arnold Smith asked on 08 Jan 2011, 08:17 PM

Hello experts,

First, I must say that the MVC Grid and Panel have been terrific timesavers. I've been able to put together an MVC project very quickly facing a tight deadline. However, I still consider myself a 'newbie' with MVC although I'm learning fast. My question will reveal a deficit of knowledge regarding postback and ajax - I come from the WebForms world. Hopefully, you can set me straight regarding best practice.

This is the architecture:

SearchController retrieves data and fills a Telerik grid. Rows are selectable in the grid. When a row is selected, I want to access the DataKey (AccountId) and pass that key to an action in EchoController.

On the grid I'm using:

    .ClientEvents(events => events.OnRowSelected("onRowSelected")) 

The javascript looks like this:

    function onRowSelected(e) { 
   
var AccountId = e.row.cells[0].innerHTML; 
    alert
(AccountId); 
 
    $
.ajax({ type: "POST", 
        url
: "/Echo/GetPatientData", 
        datatype
: "json", 
        traditional
: true, 
        data
: AccountId, 
        data
: { 'AccountId': AccountId } 
 
   
}); 
} 

The post does work, however, I'm not able to display the SearchResults view in the Echo controller. This strategy obviously is flawed.

Question: What is the right way to accomplish this?

Thanks!

Arnold

4 Answers, 1 is accepted

Sort by
0
Arnold Smith
Top achievements
Rank 1
answered on 10 Jan 2011, 03:45 PM

Hi.

How can I send the AccountId from the grid to another controller/actin for processing and then display the account details in a view constructed in that second controller? Using: window.location = "/Echo/SearchResults" doesn't work.

 

 

function onRowSelected(e) {

 

 

    var AccountId = e.row.cells[0].innerHTML;

 

    alert(AccountId);

    $.ajax(

    {

    type:

"POST",

 

    url:

"/Echo/GetPatientData",

 

    datatype:

"json",

 

    traditional:

true,

 

    data: AccountId,

    data: {

'AccountId': AccountId },

 

    success:

function () {

 

    window.location =

"/Echo/SearchResults";

 

    }

    });

}


Thanks!    
0
Arnold Smith
Top achievements
Rank 1
answered on 10 Jan 2011, 10:11 PM
Pertaining to this thread...

I have learned that a redirect will not work with an Ajax post. So, I will revise my question. How can I send an Id obtained by a Telerik grid selection to a different Controller and another action. Here is the code I'm trying to use, now. It doesn't work right because the current Controller gets prefixed on the url:

function onRowSelected(e) {

var AccountId = e.row.cells[0].innerHTML;

alert(AccountId);

window.location = '/Echo/GetPatientData' + '/' + AccountId;

}

Question: What is the best way to do this? Can you show me a code example?

Thanks!

Arnold

0
Atanas Korchev
Telerik team
answered on 11 Jan 2011, 08:46 AM
Hi Arnold Smith,

We don't have an example which fulfills your requirement. However you can check the implementation of this example. It shows how to send a value to a controller method using jQuery.

Regards,
Atanas Korchev
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
Alan
Top achievements
Rank 1
answered on 10 Feb 2011, 01:22 AM
Hi Telerik Admin,
Is the grid not record selectable?
Tags
General Discussions
Asked by
Arnold Smith
Top achievements
Rank 1
Answers by
Arnold Smith
Top achievements
Rank 1
Atanas Korchev
Telerik team
Alan
Top achievements
Rank 1
Share this question
or