i have a button on my view when fire it execute GetReport() and it execute :public ActionResult GetReport(int licenseId) by json.
now public ActionResult GetReport(int licenseId) fill my model and return it by json.
everythings are correct but i do not know how link returned model (by json) to my view?
function GetReport() {
var id = $("select#LicensesDropdown").val();
if (id == null || id == '')
return;
var inputParams = "{licenseId : '" + id + "'}";
var abc;
$.ajax({
url: "/Members/ClientMonitoring/GetReport",
type: 'POST',
dataType: 'json',
data: inputParams,
contentType: 'application/json; charset=utf-8',
success: function (msg) {
var d = Date.parseJSON(msg.StartDate);<-----------------returned filled model-------------
here i don't know h开发者_JS百科ow to fill my grid now
}
});
}
My Model---------------------------------------------------------------------------------------------------------------------
public class ReportBaseModel
{
public List<person> MonitoringLicenseModelsList { get; set; }
}
my action result----------------------------------------------------------------------------------------------------------
[HttpPost]
public ActionResult GetReport(int licenseId)
{
// fill reportmodel it contains list of data and return it by jason
return Json(reportmodel);
}
in my view --------------------------------------------------------------------------------------------------------------
@model Karanoos.Areas.Members.Models.CompositModels.ReportBaseModel
<input id="ButtonGetReport" type="button" value="Report" class="btnnormal" onclick="GetReport();" />
@{
var grid = new WebGrid(source: Model.LicensesClientsPacketModelsList,
defaultSort: "LicenseUI",
rowsPerPage: 3);
}
<div id="grid">
@grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("LicenseUI"),
grid.Column("AccountName"),
grid.Column("AppName")
)
)
When you execute the Ajax call, and get JSON you are on the client side, so you can forgot any grids and server-side controls. Only thing you can do is to take the JSON array and fill it into the plain empty HTML table in the page that is generated in the browser.
There are lot of JQuery plugins that can help you to load json into the HTML elements one of them is loadJSON plugin (see details on the http://code.google.com/p/jquery-load-json/) that enables you to load json array into the blank HTML table.
As an example see on the http://jquery-load-json.googlecode.com/svn/trunk/list.html how JSON array is taken from the server-side and loaded into the UL/LI HTML structure. you can do similar thing using the blank table.
Jovan
精彩评论