你是怎么做到的AutoPostBack在asp.net mvc的web表单的功能? [英] How do you do autopostback feature of webforms in asp.net mvc?

查看:140
本文介绍了你是怎么做到的AutoPostBack在asp.net mvc的web表单的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的WebGrid其显示列表。我也有一个包含几个项目的组合框。我想,当用户更改选择,更改的值应发布到服务器。我怎样才能做到这一点?

I have a simple webgrid which displays list. I also have a combobox which contains few items. I want that when user changes the selection, the changed value should be posted to the server. How can I do this?

任何code段将是有益的。

Any code snippets would be helpful.

在此先感谢:)

推荐答案

自动回传Web窗体与一些JavaScript来实现。这不是外的现成的MVC,但是足够简单,做你自己的。

Auto-postback in Web Forms was accomplished with some JavaScript. This is not out-of-the-box in MVC, but simple enough to do on your own.

假设你有jQuery的:

Assuming you have jQuery:

$(document).ready(function() {
    $('#someCheckBox').change(function() {
        $('#yourFormId').submit();
    });
});

这是最接近的Web窗体怎么经典作品;基本上没有当与someCheckBox的ID的复选框被选中或取消选中,提交表单ID为yourFormId'。当然,你可以将其更改您的需求。

This is "closest" to how classic Web-Forms work; basically does "When a checkbox with the ID of 'someCheckBox' is checked or unchecked, submit the form with id 'yourFormId'. You can of course change this to your needs.

这是不包括外的开箱,由于大多数开发商倾向于AJAX调用,而不是全面的后背上,我会鼓励你,如果可以做到的。什么可能是更preferable是:

This wasn't included out-of-the-box due to most developers favoring AJAX calls instead of full-blown post-backs, which I would encourage you to do if possible. What might be more preferable is:

 $(document).ready(function() {
    $('#someCheckBox').change(function() {
        $.ajax(/*make an AJAX call*/);
    });
});

这篇关于你是怎么做到的AutoPostBack在asp.net mvc的web表单的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆