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

[Solved] MVC3 grid control ajax bound select url has extra route values

7 Answers 189 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Hiram
Top achievements
Rank 1
Hiram asked on 21 Feb 2012, 08:48 PM

I have a MVC3 grid control ajax bound inside a detail page ("/Deal/Details/ASW%2093-2):
I setup the grid GridBindingSettingsBuilder.Select Method (String, String, Object) as follow:

.DataBinding(dataBinding =>
dataBinding.Ajax().Select("_PropertiesDetailsForLoanHierarchyAjax", "Deal", new
{ loanID = "<#= LOAN_ID #>" }))

 

The code generated in the client reads ("ASW%2093-2" was the ID of the Detail action):

ajax:{"selectUrl":"/Deal/_LoansForDealHierarchyAjax/ASW%2093-2?DealID=2"}

I expected to see:

ajax:{"selectUrl":"/Deal/_LoansForDealHierarchyAjax/2"}<BR>

This happens in all the Selects of this page (I have a details view grid inside this grid with the same problem). How do I get rid of the Details action route?
I have similar code in other pages (index pages) and the url created if fine.
Thanks

7 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 22 Feb 2012, 09:26 AM
Hi,

 What is LOAN_ID? How is it initialized? The syntax you are trying to use would only work if this grid is defined in the DetailTemplate of another grid.

Regards,
Atanas Korchev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Hiram
Top achievements
Rank 1
answered on 23 Feb 2012, 12:14 AM

Loan_ID is the parameter needed to get loans to load a loans grid.
I have the following hierarchy Deal -> Loan -> Property. In a Deal Details Page (/Deal/Details/ASW%2094-C2) all the URLs get build with the page Route parameter "ASW%2094-C2" in it.
In the outer grid: 
I have in View (.cshtml file): 
.DataBinding(dataBinding => dataBinding.Ajax().Select("_LoansForDealHierarchyAjax", "Deal", new { dealID = @Model.DealID.ToString() }))
I get in client:
ajax:{"selectUrl":"/Deal/_LoansForDealHierarchyAjax/ASW%2094-C2?dealID=3"}

In the inner grid:
I have in View (.cshtml): 
.DataBinding(dataBinding => dataBinding.Ajax().Select("_PropertiesDetailsForLoanHierarchyAjax", "Deal", new { loanID = "<#= LOAN_ID #>" }))
I get in client:
ajax:{%22selectUrl%22:%22/Deal/_PropertiesDetailsForLoanHierarchyAjax/ASW%252094-C2?loanID=%3c#=LOAN_ID#%3e%22}

Is it possible to not have the Details Page Route parameter in the URL?
ajax:{"selectUrl":"/Deal/_LoansForDealHierarchyAjax/3"}
instead of
ajax:{"selectUrl":"/Deal/_LoansForDealHierarchyAjax/ASW%2094-C2?dealID=3"}

By the way, the problem I had was that the controller's actions were not been called and, therefore, the grid was not loading. I thought that it had with the route since the URL had that extra information, but the problem was that the outer grid had a '>' at the end ("LoansHierarchyGrid>") of the name that caused it not to work at all. Even when I got it to work, I would like to know if I can build a cleaner URL.

Thank you

0
Atanas Korchev
Telerik team
answered on 23 Feb 2012, 08:59 AM
Hi,

 I still can't understand the exact scenario you are having. A sample project illustrating your setup would help me understand what the problem is.

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Hiram
Top achievements
Rank 1
answered on 23 Feb 2012, 08:18 PM

I thought I was very explicit, but I will make it even simpler. Assumptions: reader knows ASP.Net MVC and Telerik Grids with Ajax binding. Here is the scenario:


If I have a grid with Ajax binding in an ASP.Net MVC page with the following:

Page URL where the grid resides (this is how I get the page with the grid):

“Mydomain.com/Deal/Details/ASW%2094-C2” and that translates to DomainName/[Controller]/[Action]/[id].

Code in the View (.cshtml file) to set up grid: 
.DataBinding(dataBinding => dataBinding.Ajax().Select("_LoansForDealHierarchyAjax", "Deal", new { dealID = @Model.DealID.ToString() }))

Code that gets to the client (viewing source in browser):
ajax:{%22selectUrl%22:%22/Deal/_PropertiesDetailsForLoanHierarchyAjax/ASW%252094-C2?loanID=%3c#=LOAN_ID#%3e%22}


Please note that the URL for the action _PropertiesDetailsForLoanHierarchyAjax contains and extra parameter or id (“ASW%252094-C2”
). How do I get rid of it?????? And have a URL as this “/Deal/_LoansForDealHierarchyAjax/3 where 3 is the ID needed in the grid controller action that returns the Jason for Ajax binding (_PropertiesDetailsForLoanHierarchyAjax).

0
Atanas Korchev
Telerik team
answered on 24 Feb 2012, 12:17 AM
Hello,

The grid copies the current query string when displaying. You can try resetting that argument by passing empty string as dealID:

.DataBinding(dataBinding => dataBinding.Ajax().Select("_PropertiesDetailsForLoanHierarchyAjax", "Deal", new { dealID="", loanID = "<#= LOAN_ID #>" }))

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Hiram
Top achievements
Rank 1
answered on 24 Feb 2012, 05:28 PM
That worked in removing the page ID out of the URL. It now build the URL as this:
ajax:{%22selectUrl%22:%22/Deal/_PropertiesDetailsForLoanHierarchyAjax?loanID=%3c#=LOAN_ID#%3e%22}

Is it possible to build it like this (no query string):
ajax:{%22selectUrl%22:%22/Deal/_PropertiesDetailsForLoanHierarchyAjax/%3c#=LOAN_ID#%3e%22}

Thank you
0
Atanas Korchev
Telerik team
answered on 25 Feb 2012, 10:41 AM
Hello,

 No it is not. The default route works only for integer arguments. <#= LOAN_ID #> is a string.

Kind regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Grid
Asked by
Hiram
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Hiram
Top achievements
Rank 1
Share this question
or