Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to pass the Selected checkbox value to controller in MVC2 using Ajax/jquery
    primarykey
    data
    text
    <p>Am trying to pass the selected check box value to the control function. Please find my code</p> <p>View:</p> <pre><code> &lt;script language="javascript" type="text/javascript"&gt; $(document).ready(function () { $("#myCheckbox").change(function () { var $this = $(this); var checkboxData = $(':checked').val(); $.ajax({ url: '/Home/About', type: "POST", data: checkboxData, success: function (data) { if (data["success"]) { alert(data) } } }); }); }); &lt;/script&gt; &lt;%using (Html.BeginForm()) { %&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;%foreach (var cbName in (List&lt;Hello_World_MVC.Option&gt;)ViewData["Data"]) {%&gt; &lt;div id="AjaxDiv"&gt; //Dynamically i set the value for checkbox - Value that i using here is integer &lt;input type="checkbox" id="myCheckbox" value="&lt;%=cbName.OptionID%&gt;" /&gt; &lt;/div&gt; &lt;%} %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;%} %&gt; </code></pre> <p>This is control page:</p> <pre><code> public ActionResult About() { AboutModels ObjAM = new AboutModels();//model class name ViewData["Data"] = ObjAM.dbValue(); return View(); } [HttpPost] public ActionResult About(int id)//this parameter is my selected checkbox value.I have to get this value from ajax { AboutModels ObjAM = new AboutModels();//model class name ViewData["Data"] = ObjAM.dbValue(); ObjAM.dbUpdate(id);//I need to pass the id value to my model class to update the table return View(); } </code></pre> <p>Here i am trying to post the selected checkbox value into the DB without any onclick events.Please advice.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload