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

Load Content from Controller/Action, Pass Parameter by JavaScript

16 Answers 1430 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Hardy Wang
Top achievements
Rank 1
Hardy Wang asked on 29 Mar 2011, 12:53 AM
Hi all,

According to sample at http://www.telerik.com/help/aspnet-mvc/m_telerik_web_mvc_ui_fluent_windowbuilder_loadcontentfrom_2.html I could pass parameter to the controller/action.

But is there a way I can pass parameter(s) from client side dynamically? For example when I call open I can pass some parameters.

$('#Window').data('tWindow').open();

BTW, I can see all server side API and class references from help, but where can I find client side API references?

Thanks
Hardy

16 Answers, 1 is accepted

Sort by
0
nachid
Top achievements
Rank 1
answered on 29 Mar 2011, 07:18 AM
The code you showed does not more than opening the window
if you need to load a content from a controller/action, you need an ajaxrequest call
Search in this forum for the way to do it
0
Hardy Wang
Top achievements
Rank 1
answered on 29 Mar 2011, 01:14 PM
Hi Nachid,

Yes, I could use Ajax call to get a partial view, but the question is how can I pass content to window from client side?

Hardy
0
Mylène
Top achievements
Rank 1
answered on 21 Apr 2011, 05:17 PM
Hi Hardy,

Try this
var window = $('#Window').data('tWindow');
window.ajaxRequest("controllerName/actionName/");
window.center().open();
0
CD
Top achievements
Rank 1
answered on 26 Aug 2011, 03:39 PM
Ok, that works to load content from the controller  by returning a view, but what about passing a parameter to the controller via javascript in order to use it in the model thats returned in the view?
0
Alex Gyoshev
Telerik team
answered on 30 Aug 2011, 10:42 AM
Hi Cd,

We just improved the ajaxRequest() method to accept a second parameter, the data that you want to pass to the server, i.e.:

windowObject.ajaxRequest("/Customers/Info", { customerId: 42 });

The patched telerik.window.js is attached.

Greetings,
Alex Gyoshev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
CD
Top achievements
Rank 1
answered on 06 Sep 2011, 08:27 PM
Nice, that's very nice... will you be doing the same update for the Splitter control?
0
Alex Gyoshev
Telerik team
answered on 07 Sep 2011, 10:01 AM
Done.

splitterObject.ajaxRequest(".t-pane:first", "/Customers/Info", { customerId: 42 });

All the best,
Alex Gyoshev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
mo2011ti
Top achievements
Rank 1
answered on 13 Sep 2011, 05:17 PM
Hi,

windowObject.ajaxRequest(...)not work for me.

i replaced the   telerik.window.min.js file  in my  Scripts\2011.2.712 to the new one posted here.

the error i get is:
Microsoft JScript runtime error: Object doesn't support property or method 'ajaxRequest'

i just delete all my temporary file etc' to let my webb app to load the new js file.. still not working, any help?

Thanks

Moti

0
Alex Gyoshev
Telerik team
answered on 14 Sep 2011, 08:30 AM
Hi Moti,

Is windowObject defined and pointing to the client-side object of the window? Like so:

$("#WindowName").data("tWindow").ajaxRequest(...);

If it is, please provide more detail about how you are using the window.

Regards,
Alex Gyoshev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
mo2011ti
Top achievements
Rank 1
answered on 14 Sep 2011, 01:22 PM
Hi Alex,

thanks for sending this, i made a mistake and call   $("#WindowName").ajaxRequest(...);

i fix it to :
$("#WindowName").data("tWindow").ajaxRequest(...);
and work very nice.

Thank you for yor reply.

Moti
0
Nate
Top achievements
Rank 1
answered on 16 Sep 2011, 07:10 PM
Hey, so is the second parameter a JSON object? How do I evaluate the object on the controller side? Can you give me a sample of the action method that handles it?

Thanks,
0
Georgi Krustev
Telerik team
answered on 19 Sep 2011, 09:05 AM
Hello Nate,

The second parameter is the URL to the Action. The third one is the data, which you want to send to the server and it should be JSON:

[JavaScript]:

splitterObject.ajaxRequest(".t-pane:first", "/Customers/Info", { customerId: 42 });

And the send customerId is evaluated in this way on the server:
[HttpPost]
public ActionResult Info(int customerId) {
 
//customerId is 42
 
}


Kind regards,
Georgi Krustev
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
cp
Top achievements
Rank 1
answered on 14 Oct 2011, 11:53 PM
I'm thinking you need to POST instead of GET as well as add the content type in the js file.

Thanks,
0
Sreenivas
Top achievements
Rank 1
answered on 16 Nov 2011, 10:44 PM
I am seeing additional unknown parameter in the HTTP request.  I am using version 2011.2.914

Controller action:
[HttpGet]
public ActionResult ChangePasswordView(string userName)
{
    MembershipUser user = _userService.Get(userName);
    return View(PartialView("ChangePassword", user));
}

javascript code:
function password_onClick(e) {
    var username = e.id.split("_")[1];
    if (username != undefined || username != null) {
        var window = $('#ChangePasswordWindow').data('tWindow');
        window.ajaxRequest("ChangePasswordView", { userName: username });
        window.center().open();
    }
}

Firebug shows the following request:
     
"NetworkError: 500 Internal Server Error - http://localhost:58694/UserAdministration/ChangePasswordView?userName=natelunde&_=1321479858286"

What is the "&_=1321479501969" at the end?  How do I suppress it?

Thanks in advance.
0
MiBu
Top achievements
Rank 1
answered on 03 May 2012, 03:53 PM
What is the "&_=1321479501969" at the end?  How do I suppress it? 

I have the same problem. So far I couldn't find a workaround to send data to controller action. Is there any way?

Thanks,
mbudimir
0
Jeremy Wiebe
Top achievements
Rank 1
answered on 18 May 2012, 02:51 AM
That extra query parameter on the end is to prevent your browser from caching future requests to the same resource.  Try changing your build to "Release" mode and seeing if the parameter still gets tacked on.  I'm pretty sure it'll go away.  It's there so that during development you don't have problems with the browser caching things and causing problems.
Tags
Window
Asked by
Hardy Wang
Top achievements
Rank 1
Answers by
nachid
Top achievements
Rank 1
Hardy Wang
Top achievements
Rank 1
Mylène
Top achievements
Rank 1
CD
Top achievements
Rank 1
Alex Gyoshev
Telerik team
mo2011ti
Top achievements
Rank 1
Nate
Top achievements
Rank 1
Georgi Krustev
Telerik team
cp
Top achievements
Rank 1
Sreenivas
Top achievements
Rank 1
MiBu
Top achievements
Rank 1
Jeremy Wiebe
Top achievements
Rank 1
Share this question
or