需要更新的复选框值数据库表,当我点击复选框()不交回来MVC2 [英] Need to update the check box value to db table when i click the checkbox() without post back in MVC2

查看:91
本文介绍了需要更新的复选框值数据库表,当我点击复选框()不交回来MVC2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<input type="checkbox" name="n" value=1 />
<input type="checkbox" name="n" value=2 />
<input type="checkbox" name="n" value=3 />

我上面的复选框,当我选择这个,我需要无需后期更新数据库表背。 请解释一下。如果有可能,你可以说的jQuery或AJAX方法来解决我的问题。

I have above checkbox when i select the this i need to update the DB table without post back. Please explain.. If possible you can say jquery or ajax method to solve my problem

推荐答案

您需要做某种请求到服务器,无论是从一个表单按钮或一个Ajax POST一个POST或GET请求。

You have to do some sort of request back to the server, whether it's a POST from a form button or an Ajax POST or GET request.

表单按钮:

<form action="/MyApp/HandleClick/" method="post">
    <input type="checkbox" name="SelectedObject" value="cbValue"/>
    <button type="submit">Submit</button>
</form>

或者,阿贾克斯(使用jQuery):

 jQuery('input[name=SelectedObject]').click(function() {
     jQuery.ajax({
         url: '/MyApp/HandleClick/',
         data: {
             SelectedObject: this.value,
         }
         success: function() {
             // Process success data...
         }
     });
 });

然后控制器:

Then your controller:

public class MyAppController : Controller
{
    [HttpPost]
    public ActionResult HandleClick(string value)
    {
        // Handle persisting value to database...

        // If posting
        return RedirectToAction("OtherAction");

        // If Ajax
        return Json("Success!");
    }
}

这是最简单的例子 - 不能回答更没有你所要完​​成什么更多详细信息

That's the simplest example - can't answer more without more details about exactly what you're trying to accomplish.

这篇关于需要更新的复选框值数据库表,当我点击复选框()不交回来MVC2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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