javascript - Pass parameters to actionresult from jsonresult -
i wrote code filter results following image ,
once after filter want send model values of following field parameters controller method, can call method once click generate report button
this view file
@model project_name.models.searchvm .... @using (html.beginform()) { @html.antiforgerytoken() @html.validationsummary(true, "", new { @class = "text-danger" }) .... <div class="row"> <div class="col-xs-6"> <div class="form-group"> @html.labelfor(m => m.type, htmlattributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @html.dropdownlistfor(m => m.type, model.typelist, "select type", new { @class = "form-control" }) @html.validationmessagefor(model => model.type, "", new { @class = "text-danger" }) </div> </div> </div> </div> ............... <div class="row"> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="button" value="generate report" class="btn btn-success submit" onclick="location.href='@url.action("reportexport", "home", new { type = model.type , ............. })'" /> <button id="search" type="button" class="btn btn-success submit">search</button> </div> </div> </div> } <table class="table"> <thead> <tr> <th>id</th> <th>product name</th> <th>type</th> ......... <th>action</th> </tr> </thead> <tbody id="table"></tbody> </table> <table id="template" class="table" style="display: none;"> <tr> <td></td> <td></td> <td></td> ........ <td><a>edit</a></td> </tr> </table> @section scripts { @scripts.render("~/bundles/jqueryval") @scripts.render("~/bundles/jqueryui") <script type="text/javascript"> $(function () { $('.datepicker').datepicker({ dateformat: 'yy/mm/dd', changemonth: true, changeyear: true, yearrange: '1910:2015' }); }); </script> <script type="text/javascript"> var url = '@url.action("fetchproducts")'; var editurl = '@url.action("edit")'; var type = $('#type'); .............. var template = $('#template'); var table = $('#table'); $('#search').click(function () { table.empty(); $.getjson(url, { type: type.val(), ......, function (data) { $.each(data, function (index, item) { var clone = template.clone(); var cells = clone.find('td'); cells.eq(0).text(item.id); cells.eq(1).text(item.name); cells.eq(2).text(item.type); ........................ cells.eq(7).text(item.status); var href = '@url.action("edit")' + '/' + item.id; cells.eq(8).children('a').attr('href', href); table.append(clone.find('tr')); }); }); }); </script> }
i want call , send parameters reportexport method once click generate report button
but i'm getting null values , think because of i'm doing searching using json , how can type value , send parameter ,
[httpget] public actionresult reportexport(string id, string type, ...........) {
your 'generate report' button includes @url.action("reportexport", "home", new { type = model.type, ...
razor code. razor code parsed on server before sent view generating route values based on initial values of model, not edited values.
you can use jquery build url based on form controls.
html
<input type="button" id="report" data-baseurl="@url.action("reportexport", "home")" value="generate report" class="..." />
script
$('#report').click(function() { // build url var url = $(this).data('baseurl') + '?type=' + $('#type').val() + '&category=' + $('#category').val() + ......; // redirect location.href = url; });
Comments
Post a Comment