c# - How to Bind Data in Webgrid usig PartialView in ASP.net MVC -
iam new .net mvc. need bind data webgrid return using partialview()
,or if possible return using json
,now code execute on dropdown
change,but not bind values in web grid.
javascript,model,controller codes shown below:
script
<script type="text/javascript"> $(document).ready(function () { $("#cust_id").change(function () { firstddlvalue = $("#cust_id").val(); $.post('@url.action("selectcustomerbyid", "admin")', {secondvalue:firstddlvalue }, function (receiptlist) { alert(firstddlvalue); $('#divgrid').html(receiptlists); }); }); }); </script>
view:
<div id="divgrid" style="margin-top: 15px;"> @{ var grid = new webgrid(model, canpage: true, rowsperpage: 5, selectionfieldname: "selectedrow", ajaxupdatecontainerid: "gridcontent"); grid.pager(webgridpagermodes.nextprevious);} <div id="gridcontent"> @grid.gethtml( tablestyle: "webgrid-table", headerstyle: "webgrid-header", footerstyle: "webgrid-footer", alternatingrowstyle: "webgrid-alternating-row", selectedrowstyle: "webgrid-selected-row", rowstyle: "webgrid-row-style", columns: grid.columns( grid.column("id", "id", style: "id"), grid.column("cust_name", "cust name", style: "pname"), grid.column("pay_amount", "pay_amount", style: "icode"), grid.column("pay_mode", "pay_mode", style: "iname"), grid.column("bank_name", "bank_name", style: "weight"), grid.column("bank_address", " bank_address", style: "makingcharge"), grid.column("chequeno", "chequeno", style: "certification"), grid.column("cheque_date", " cheque_date", style: "price"), grid.column("date", "date", style: "price"), grid.column("edit", "", @<a href='../admin/editreceipt?id=@item.id' ><img src="~/images/edit.png" alt='edit' /></a>, style: "width:10%"), grid.column(header: "delete", format: @<text><a href="@url.action("deletereceipt", "admin", new { id = item.id })" onclick="javascript:return confirm('are sure you'd delete product?');"><img src="../images/delete.png" alt='delete' /></a></text>) )) @if (grid.hasselection) { receipt = (jewellaryweb.models.receipt)grid.rows[grid.selectedindex].value; <b>id</b> @receipt.id<br /> <b>name</b> @receipt.cust_name<br /> <b>amount</b> @receipt.pay_amount<br /> <b>paymode</b> @receipt.pay_mode<br /> <b>bankname</b> @receipt.bank_name<br /> <b>bankaddress</b> @receipt.bank_address<br /> <b>chequenumber</b> @receipt.chequeno<br /> <b>chequedate</b> @receipt.cheque_date<br /> } </div>
controller:
public actionresult selectcustomerbyid(receipt model,string secondvalue) { int custid = 0; if (secondvalue != "") custid = convert.toint32(secondvalue); observablecollection<receipt> receiptlist = new observablecollection<receipt>(); receipt receipt = new models.receipt(); model.receiptlist = receipt.getreceiptlistbycustid(custid); return partialview(model.receiptlist); }
i found answer modified script , use paritalview bind data in gird solution code is:
script
<script type="text/javascript"> $(document).ready(function () { $("#cust_id").change(function () { firstddlvalue = $("#cust_id").val(); $.get('@url.action("selectcustomerbyid", "admin")', { secondvalue: firstddlvalue }, function (receiptlist) { $('#gridcontent').html(receiptlist); }); }); }); </script>
i create new _recepitgrid.cshtml partialview , write code webgrid same in main view.
controller
public actionresult selectcustomerbyid(receipt model, string secondvalue) { int custid = 0; if (secondvalue != "") custid = convert.toint32(secondvalue); observablecollection<receipt> receiptlist = new observablecollection<receipt>(); receipt receipt = new models.receipt(); receiptlist = receipt.getreceiptlistbycustid(custid); return partialview("_recepitgrid", receiptlist); }
now works fine..
Comments
Post a Comment