2011-09-29 95 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

相關問題