views:

297

answers:

3

So i'm trying out MVC after only playing with it some time ago.

Need to find the best way to selectively show and hide sections (divs, etc) on clicking or changing a value of a control, but not having to post back, i.e. javascript?

Any suggestions.

+5  A: 

Use jQuery. You can use a jQuery Event to detect a click and then hide or show divs.

So, You have a button called "HideDiv" and "DivToHide" is the div you wish to hide.

$("#HideDiv").click(function() {
   $("#divToHide").hide();
};

It's that easy. Can't really go in-depth here but check out their tutorials: http://docs.jquery.com/Tutorials or browse this site: http://www.learningjquery.com/category/levels/beginner

jQuery actually comes with ASP.Net MVC, check the scripts folder of a new MVC project and you'll see it in there. This site using jQuery and MVC :) So your browsing a sample of what is possible with it

Damien
Where's the best quickstart resource for jQuery?
Jan de Jager
just updated my answer to include recommendations
Damien
+1  A: 

You can do same way as you are doing it with normal asp.net application using javascript. I think javascript is best as its fast and works on client side.

If you are having specific requirement then please put the specific requirement here. You can use jquery or MooTools if you want some animation.

jalpesh
+1  A: 

You can use jQuery. It is included with the standard MVC project template.

$("#myButtonId").click(function () {
  $("#myDivId").toggle();
});

See more at the jQuery docs for toggle.

Marpe