tags:

views:

23

answers:

1

Hello,

I'd like to know if it's possible to get postback effect like in ASP.NET webform without using JavaScript. I've a collection of object to display on the view. I'd like to place a dropdownList element somewhere on that view, such as, if I select a different item, then the postback occures and a new filtered collection is sent to the view.

I know for sure that's not automatic. However, I wonder if, by means of form element or whatever other means, that can be done without using javascript (Unobtrusive pattern).

Thanks for helping

+2  A: 

Nope, not entirely without javascript.

You need to bind to the change event of the <SELECT>, by javascript, or set the onchange attribute to execute some javascript, to simply cause a this.form.submit();.

Don't be too afraid of javascript, tho. This sounds like a great place where it'll act exactly the way you want if javascript is enabled, and if it isn't, the site will still work, only the user will have to manually submit the form.

David Hedlund
@David Hedlund: I decided these days not to use javascript at all untill I really understand deeply how ASP.NET MVC works. Well, this is one of those cases where I can't really get away without javascript.
Richard77
@Richard77: well i'll leave that decision up to you then, but yes, if you want to do this, you'll have to use javascript. if you knew it couldn't be done in HTML, but thought you might be missing out on some mvc.net-specific feature, then look at it this way: the only reason it can be done in webforms is that webforms generate javascript. and you can certainly write an mvc helper that generates a select list + javascript as well.
David Hedlund
@David Hedlund: I agree 100% with you. I'm not using javascript these days just to get to know MVC capabilities (in the learning process). But, in a real project, I'll use javascript. At least, I've learned what MVC can or cannot do. Thanks
Richard77
@Richard77 You do it the right way. Even if you plan to use javascript you should always start with a non js version and enhance the view for js browser after that. This way non js clients (ie the google bot) can access the content of your site.
Malcolm Frexner
@Richard77 - I think javascript (and jQuery) is going to be a big part of having a rich UI in ASP.NET MVC. It's not meant to be entirely independent of javascript.
dave thieben