2011-09-29 107 views
-1

我有我的观点一个按钮时,火就执行GetReport(),它执行:由JSON公众的ActionResult GetReport(INT licenseId)。如何将模型从json传递到视图?

现在公众的ActionResult GetReport(INT licenseId)填写我的模型,并通过JSON返回。

万物是正确的,但我不知道如何链接返回模式(通过JSON)我的看法?

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 how to fill my grid now 

    } 
}); 

}

我的模型------------------------------------ -------------------------------------------------- -------------------------------

public class ReportBaseModel 
    { 
    public List<person> MonitoringLicenseModelsList { get; set; } 

} 

我的行动结果--------- -------------------------------------------------- -----------------------------------------------

[HttpPost] 
public ActionResult GetReport(int licenseId) 
    { 
     // fill reportmodel it contains list of data and return it by jason 

     return Json(reportmodel); 
    } 

在我看来---------------------------------------------- -------------------------------------------------- --------------

@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") 
    ) 
) 

回答

1

当你执行Ajax调用,并获得JSON你是在客户端,让你可以忘记任何网格和服务器边控制。唯一可以做的就是取出JSON数组并将其填充到浏览器中生成的页面中纯粹的空HTML表格中。

有很多jQuery插件,可以帮助你JSON加载到HTML元素的其中之一是loadJSON插件(见的http://code.google.com/p/jquery-load-json/细节),使您可以JSON数组加载到空白HTML表格。

作为一个例子对http://jquery-load-json.googlecode.com/svn/trunk/list.html看到如何JSON阵列从服务器侧取出并装载到UL/LI HTML结构。你可以使用空白表做类似的事情。

Jovan

相关问题