views:

41

answers:

4

Hello Friends,

I have a questions.. when initially page load I have two radio button in the page..

        Add
        Edit

when I select Add radio button I need to go the controller Action Add

        $("#Add").change(function () {
// what should I write here to hit the controller?

        });

Thanks

+1  A: 
window.locatation.href = "<%= Url.Action("Add", "Controller") %>";

That is in the case the script is in the view so you can use the advantage of the Url.Action method. Otherwise it's just something like

window.location.href = "/Controller/Add";
Trimack
+1  A: 
window.location.href = '/my/url/to/be/called';
zolex
+2  A: 

Well technically if you want to to do something with the controller, like get/send data you'd use the ol' ajax call

This call will vary depending on get/post type. Look up this function for more details but here's an idea.

$.ajax({

url: 'directorie/controllername' type:Get success: function(data) {

do some stuff with data } });

but just going to a controller is pretty simple, it's doing something with the controller that makes it meaningful.

Ehsan
+1  A: 

If I understand correctly your question, you want to activate an event when you click on your radio button. If so, you are probably looking for the .trigger() function.

Your code would be something like this :

$("#Add").change(function () {
    $("#WhateverController").trigger('click');
});
Gabriel