开发者

Handling autopostback in ASP.NET MVC

How do I handle autopoatback in ASP.NET MVC? Suppose I have a textbox. I enter a value in it, I need to check if the value exists in some table in the database. So in ASP.NET forms I can set AutoPostBack = true and handle the TextBox.TextChanged event. How do I do it here?

And what are the pros and cons开发者_如何学Go of using ASP.NET server control in MVC?


The short answer is - don't use ASP.NET server controls in ASP.NET MVC. ViewState is not supported in MVC and using 'codebehind' files completely against the methodology of MVC - you don't 'handle events' you submit values to a controller which then handles the logic and returns a view.

As you don't seem clear on what MVC is, I would suggest that before embarking on an MVC project you first read Comparing Web Forms And ASP.NET MVC by Dino Esposito (MSDN). This should give you an overview on the differences between web forms and MVC. If you then wish to use MVC I would strongly suggest you visit http://www.asp.net/mvc/ and watch and read the tutorials to get a flavour for it. It's not something you can just dive into as it is a very different framework to standard web forms and requires a whole new mindset. Once you've done that, get a good book, such as Steve Sanderson's Pro ASP.NET MVC Framework (V2 is released in May, so wait for that).


There are no postbacks in ASP.NET MVC. What you need to do here is an AJAX call to a Controller action on the server.

Here's an example http://www.hanselman.com/blog/ASPNETMVCPreview4UsingAjaxAndAjaxForm.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜