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

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

3
  • I'm not really sure what you're asking - do you want to know how to handle the POST and bind to a model? Commented Jun 30, 2011 at 20:47
  • Thank you for your respond.. Yes Leni Commented Jun 30, 2011 at 20:48
  • i want to know how to handle the checkbox value to update the DB without postback Commented Jun 30, 2011 at 21:12

3 Answers 3

2

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 button:

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

Or, Ajax (with 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.

Sign up to request clarification or add additional context in comments.

Comments

0
$('#checkboxid').click(function(){
 $.ajax({ url: 'your_url_for_receiving_data',
type: 'POST',
data: { checkbox: $('#checkboxid').attr('checked') },
success: function(o) { alert('saved'); }
});

just create code behind in mvc2 where you will get value from request and save it to db

Comments

0

" />

in controller

public ActionResult(string value) { return View();

} it is help you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.