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

Supplying route values from javascript?

1 Answer 289 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 07 Aug 2012, 01:35 PM
Hi.  I have an MVC3 application programmed in VB.NET.

In this MVC3 application, I have a controller.  The controller's JSON action has 3 parameters as specified below:

        Function JSONRetrieveDocuments(
            ByVal contactId As Guid,
            ByVal includeLoanBasedDocuments As Boolean,
            <DataSourceRequest()> request As DataSourceRequestAs ActionResult

As part of a Grid, I build a route value dictionary as part of the function that creates the CrudOperationBuilder:

        Public Function CreateCrudOperationBuilder(cob As Kendo.Mvc.UI.Fluent.CrudOperationBuilderAs Kendo.Mvc.UI.Fluent.CrudOperationBuilder
            Dim theRouteValueDictionary As New RouteValueDictionary()
 
            theRouteValueDictionary.Add("contactId", Request.QueryString("contactId"))
	    'theRouteValueDictionary.Add("includeLoanBasedDocuments", ???
           Return cob.Action("JSONRetrieveDocuments""ContactBasedDocument", theRouteValueDictionary)         End Function

When making the call to JSONRetrieveDocuments, I want to be able to populate the includeLoanBasedDocuments parameter of the controller's action by simply returning the checked status of a checkbox...  so I created this javascript function:

    function ShouldIncludeLoanBasedDocuments() {
        return $("#cbIncludeLoanBasedDocuments")[0].checked;
    }


I'm curious 
a) how do I supply the result of the javascript function to the route values?
b) am I following best practices on this one?   It seems like this would be a common operation, but I couldn't find any documentation on it.

Thanks,

Jason

1 Answer, 1 is accepted

Sort by
0
Jason
Top achievements
Rank 1
answered on 07 Aug 2012, 05:53 PM
The solution that I found was to use the Data() function of the CrudOperationBuilder and construct the parameters in javascript instead of .net code.
Tags
Data Source
Asked by
Jason
Top achievements
Rank 1
Answers by
Jason
Top achievements
Rank 1
Share this question
or