2012-04-05 76 views
0

我使用MVC 3 + Razor。我有一個名爲Details的MVC視圖。我從SQL服務器數據庫表中取回並顯示了詳細信息數據。我有一個可點擊的<a/>列「類型」。點擊Type Anchor鏈接顯示一個Jquery Popup。使用jQuery對話框在mvc視圖中編輯表格

| type  | date | completed | 
|________________________________ _| 
|   |   |   | 
| sample | 1/1/2012 |   | 
|(Clickable)| 
  1. 如何Retreive在SQL服務器與點擊的元素從表中整行數據,並顯示該數據的jQuery的Dialog.Every類型字段都有一個與之關聯的ID。

  2. 我在Jquery Dailog上有一個複選框。如果選中,則視圖中的已完成列必須包含當前日期,並且必須更新數據庫表(其中包含日期字段)。

尋找代碼示例或鏈接或教程 - 沒有找到任何編輯和添加功能。

+0

你簽出的jqGrid? http://trirand.net/default.aspx可能有你正在尋找的功能。 – 2012-04-05 16:31:50

回答

0

我不熟悉asp.net或剃鬚刀,但我知道使用jQuery時,您首先會向服務器發出ajax請求,其中腳本將加載sql數據,將其轉換爲JSON字符串併發送它回到了jQuery。 jQuery然後可以解析JSON並填充字段。

在jQuery中處理日期(通常爲javascript)可能會非常棘手,因爲它基於客戶端的機器而不是服務器。我會建議再次運行ajax,讓服務器檢查當前日期並處理數據庫更新。

0

使用局部視圖彈出,根據您的需求製作UI,並將行細節作爲模型傳遞給此局部視圖。

你的表HTML的樣子,

<tr id="@model.rowid"> 
     <td> 
      sample 
      (<a onclick="RowDetails(@model.rowid)">Clickable</a>) 
     </td> 
     <td> 
      1/1/2012 
     </td> 
     <td> 
     </td> 
    </tr> 

調用JavaScript功能上Clicktable喜歡的點擊,

function RowDetails(RowId) { 
     $("#divDetails").load('/yourController/rowdetail', { id: RowId }).dialog({ 
      modal: true, 
      title: "Row Detail", 
      height: 400, 
      width: 600, 
      buttons: { 
       "Ok": function() { 
        var isComplete = 0; 
        if ($("#rowComplete").is(":checked")) { isComplete = 1; } 
        $.get("/yourController/RowComplete", { id: RowId, isChk: isComplete }, function (d) { 
         $("#" + RowId).before(d).remove(); 
         $("#" + RowId).hide().fadeIn('slow'); 
        }); 
        $(this).dialog('close'); 
       } 
      } 
     }); 
    } 

和控制器一樣,

public ActionResult rowdetail(int id) 
{ 
// code to get row from databse 
// return this row as object to partial view 
return("partial view for row details", Object); 
} 

public ActionResult RowComplete(int id, int chk) 
{ 
// code to update row from databse 
// return this row as object 
return("pass updated row", Object); 
}