Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can i pass parameter from jqgrid to controller with datapost (using MVC4 and asp.net )
    text
    copied!<p>I want to pass some selectedValue from view : jqgrid to controller, can i do that with post data? please help me I have 3 cascadind dropdownlist and i want to filter my grid with those selectedValue how can I pass parameters ??</p> <pre><code> @model Project.Models.FRHEntities @{ ViewBag.Title = ""; } @section featured { &lt;section class="featured"&gt; &lt;div class="content-wrapper"&gt; &lt;hgroup class="title"&gt; &lt;h1&gt;@ViewBag.Title&lt;/h1&gt; &lt;h2&gt;@ViewBag.Message&lt;/h2&gt; &lt;/hgroup&gt; &lt;/div&gt; &lt;/section&gt; } @Styles.Render("~/Content/jquery.jqGrid/ui.jqgrid.css") @Styles.Render("~/Content/blitzer/jquery-ui-1.10.3.custom.css") &lt;script src="@Url.Content("~/Scripts/jquery-2.0.3.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.jqGrid.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/i18n/grid.locale-fr.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Content/js/ui/minified/jquery.ui.autocomplete.min.js")" type="text/javascript" &gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Content/js/ui/minified/jquery.ui.datepicker.min.js")" type="text/javascript" &gt;&lt;/script&gt; @section Scripts { @Scripts.Render("~/bundles/jqueryval") @Scripts.Render("~/bundles/jqueryui") @Styles.Render("~/Content/themes/base/css") &lt;script type="text/javascript"&gt; $(document).ready(function () { $("#Dob").datepicker({ changeMonth: true, changeYear: true }); }); &lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function () { $("#Dob2").datepicker({ changeMonth: true, changeYear: true }); }); &lt;/script&gt; } &lt;h2&gt;@ViewBag.Message&lt;/h2&gt; &lt;table style="width: 100%;" &gt; &lt;tr aria-atomic="False"&gt; &lt;td&gt;date début :&lt;/td&gt; &lt;td&gt;&lt;input id="Dob" type="text" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;date fin :&lt;/td&gt; &lt;td&gt;&lt;input id="Dob2" type="text" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Activité : &lt;/td&gt; &lt;td&gt;@Html.DropDownList("Activites", (SelectList)ViewBag.SelectList, "selectionnez --", new { id = "Activites" }) &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Service :&lt;/td&gt; &lt;td&gt;&lt;select id="Services" name="services" &gt;&lt;option&gt;Selectionnez --&lt;/option&gt;&lt;/select&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Client :&lt;/td&gt; &lt;td&gt;&lt;select id="Clients" name="clients"&gt;&lt;option&gt;Selectionnez -- &lt;/option&gt;&lt;/select&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input class ="button" id="ButtonSubmit" type="button" value="Visualiser" onclick="javascript: afficher_cacher('rapport')" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input class="button" id="Exporter" type="button" value="Exporter" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;table id="activitelist"&gt;&lt;/table&gt; &lt;div id="activitelist_pager"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; &lt;!-- $(document).ready(function () { $('#Activites').change(function () { ChangeActivite(); }); $('#Services').change(function () { ChangeService(); }); $('#Clients').change(function () { ChangeClient(); }); $('#activitelist').hide(); $('#ButtonSubmit').hide().click(function () { show(); }); }); function ChangeClient() { var selectedValue = $('#Activites option:selected').val(); var selectedValue2 = $('#Services option:selected').val(); var selectedValue3 = $('#Clients option:selected').val(); if ($.trim(selectedValue).length &gt; 0) { $('#ButtonSubmit').show(); } else { $('#ButtonSubmit').hide(); $('#ClientInfo').empty(); } } function ChangeActivite() { var selectedValue = $('#Activites option:selected').val(); if ($.trim(selectedValue).length &gt; 0) { // GetClients(selectedValue); GetServices(selectedValue); } } function ChangeService() { var selectedValue = $('#Activites option:selected').val(); if ($.trim(selectedValue).length &gt; 0) var selectedValue2 = $('#Services option:selected').val(); if ($.trim(selectedValue).length &gt; 0) { // GetClients(selectedValue); GetClients(selectedValue,selectedValue2); } } function GetServices(activiteID) { $.ajax({ url: '@Url.Action("Services", "Display")', data: { activiteID: activiteID }, type: 'post', cache: false, async: false, dataType: 'json', success: function (data) { if (data.length &gt; 0) { $('#Services').empty(); $('#Services').append($('&lt;option&gt;&lt;/option&gt;').val('').text('Selectionnez--')); $.each(data, function (i, item) { $('#Services').append($('&lt;option&gt;&lt;/option&gt;').val(item.Key).text(item.Value)); }); } } }); } function GetClients(activiteID,service) { $.ajax({ url: '@Url.Action("Clients", "Display")', data: { activiteID: activiteID , service : service}, type: 'post', cache: false, async: false, dataType: 'json', success: function (data) { if (data.length &gt; 0) { $('#Clients').empty(); $('#Clients').append($('&lt;option&gt;&lt;/option&gt;').val('').text('Selectionnez--')); $.each(data, function (i, item) { $('#Clients').append($('&lt;option&gt;&lt;/option&gt;').val(item.Key).text(item.Value)); }); } } }); } function show() { $("#activitelist").jqGrid({ url: '@Url.Action("LinqGridData", "Display")', postData: { activite : "1-COURRIER ENTRANT" }, datatype: 'json', mtype: 'POST', colNames: ["Activité", "Service", "Client", "volume", "delta", "temps moyen", "temps total"], colModel: [ { name: "Activité", index: "Activité" }, { name: "Service", index: "Service" }, { name: "Client", index: "Client" }, { name: "vol", index: "vol" }, { name: "delta_", index: "delta_" }, { name: "tempsmoy_", index: "tempsmoy_" }, { name: "tempstot", index: "tempstot" }, ], pager: $('#activitelist_pager'), rowNum: 25, rowList: [5, 10, 25, 50], height: 'auto', width: '800', sortname: 'Activite', sortorder: "ASC" }); $("#activitelist").jqGrid('navGrid', '#activitelist_pager', { add: false, edit: false, del: false, search: false }); } &lt;/script&gt; </code></pre> <p>this is action method :</p> <p>public ActionResult LinqGridData(string activite , string sidx, string sord, int page, int rows) {</p> <pre><code> var context = new FRHEntities(); int pageIndex = Convert.ToInt32(page) - 1; int pageSize = rows; int totalRecords = context.productivites.Count(); int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize); var jsonData = new { total = totalPages, page = page, records = totalRecords, rows = frh.productivites.AsEnumerable().Where(n =&gt; n.Activité == activite).Select(n =&gt; new { id = n.activitéID, cell = new string[] { n.Activité, n.Service.ToString(), n.action, n.vol.ToString(), n.delta_.ToString(), n.tempsmoy_.ToString(), n.tempstot_.ToString() } }).ToArray() }; return Json(jsonData, JsonRequestBehavior.AllowGet); } </code></pre>
 

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