需要更新的复选框值数据库表,当我点击复选框()不交回来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.

阅读全文

相关推荐

最新文章