Code:
<% using (Ajax.BeginForm("Index", null, new AjaxOptions{UpdateTargetId = "myTable",}, new { ID = "form1"})) {%>
<%:Html.CheckBox("chkIzlistajSve", false)%> Izlistaj sve <br/>
<%:Html.DropDownList("ddlKorisnici", (IEnumerable<SelectListItem>)ViewData["korisnici"])%>
<table id="my Table">
<tr>
<th>
Korisnik
<th>
Ulica
</th>
<th>
Broj
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%: item.KorisnikNaziv%>
</td>
<td >
<%: item.Ulica%>
</td>
<td>
<%: item.Broj)%>
</td>
</tr>
<% } %>
</table>
<% } %>
<% using (Ajax.BeginForm("Index", null, new AjaxOptions{UpdateTargetId = "myTable",}, new { ID = "form1"})) {%>
<%:Html.CheckBox("chkIzlistajSve", false)%> Izlistaj sve <br/>
<%:Html.DropDownList("ddlKorisnici", (IEnumerable<SelectListItem>)ViewData["korisnici"])%>
<table id="my Table">
<tr>
<th>
Korisnik
<th>
Ulica
</th>
<th>
Broj
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%: item.KorisnikNaziv%>
</td>
<td >
<%: item.Ulica%>
</td>
<td>
<%: item.Broj)%>
</td>
</tr>
<% } %>
</table>
<% } %>
i JQuery:
Code:
$(document).ready(function () {
$("#chkIzlistajSve").click(function () {
var formData = jQuery("#form1").serialize();
var boolSve = $("#chkIzlistajSve").is(":checked");
jQuery.ajax({
url: "@Url.Action('Index')",
type: "POST",
data: formData,
cache: false,
dataType: "json",
success: function () {
$("#chkIzlistajSve").attr("checked", boolSve);
}
});
});
$(document).ready(function () {
$("#chkIzlistajSve").click(function () {
var formData = jQuery("#form1").serialize();
var boolSve = $("#chkIzlistajSve").is(":checked");
jQuery.ajax({
url: "@Url.Action('Index')",
type: "POST",
data: formData,
cache: false,
dataType: "json",
success: function () {
$("#chkIzlistajSve").attr("checked", boolSve);
}
});
});
Znači, cilj je da se onClick chekbox-a "Izlistaj sve" forma postuje i da se u action metodu preuzmu vrednosti iz checkbox-a (da li je čekiran) i selektovana vrednost iz dropdown liste.
Action metod izgleda ovako:
Code:
[HttpPost]
public ActionResult Index(FormCollection values)
{
bool izlistajSve=bool.Parse(Request.Form["chkIzlistajSve"].ToString());
int korisnikid = Int32.Parse(Request.Form["ddlKorisnici"].ToString());
....
}
[HttpPost]
public ActionResult Index(FormCollection values)
{
bool izlistajSve=bool.Parse(Request.Form["chkIzlistajSve"].ToString());
int korisnikid = Int32.Parse(Request.Form["ddlKorisnici"].ToString());
....
}
Kada postujem formu na ovaj način, dobijam vrednosti sa forme i sve je u redu, ali kada odradim da se promenom selektovane vrednosti dropdown liste ( znači:
Code:
$("#ddlKorisnici").change(function () {"identičan kod kao i kod checkbox-a"});
) forma postuje i da se u istom post metodu preuzmu vrednosti, sve Request.Form[""] vrednosti su null.$("#ddlKorisnici").change(function () {"identičan kod kao i kod checkbox-a"});
U čemu je razlika??? Pomagajte...