2016-02-10 21 views
0

以下代碼創建了列,但如何隱藏除具有登錄人員ID的行之外的所有行。每行有一個我想保留的編輯功能。我希望能夠在表中顯示一行,具體取決於登錄人的ID

@grid.GetHtml( 
     tableStyle: "grid", 
    headerStyle: "head", 
    alternatingRowStyle: "alt", 
    columns: grid.Columns(    
      grid.Column(format:@<ahref="~/[email protected]">Edit</a>), 
      grid.Column("Name"), 
      grid.Column("Skills"), 
      grid.Column("Email"), 
      grid.Column("Reel"), 
      grid.Column("Country"), 
      grid.Column("Level"), 
      grid.Column(format:@<ahref="~/[email protected]">Delete</a>) 
+0

限制你的控制器,只顯示是誰英寸 –

+0

感謝TK記錄的人的記錄,但在編碼作爲一個總NUBE是存在的,你可以試玩限制任何實際的代碼用控制器? – animator

回答

0

我不確定你使用的是什麼版本的MVC,或者你正在使用什麼認證。它看起來像你有一個單獨的表,其中包含用戶的詳細信息。在你的控制器做這樣的事情:

public ActionResult Index() 
{ 
    using (YourContext db = new YourContext()) 
    { 
    //I'm not sure where you are getting the id of the logged in person. 
    //Also for "Find" to work, id must be the primary key of the table. 
    userinfo u = db.UserInfoTable.Find(id); 
    return View(u); 
    } 
} 

這隻會傳遞一個記錄到您的視圖。你永遠不應該依賴客戶端來提供安全性。隱藏你不希望人們看到的記錄是不安全的。查看您的源代碼將顯示您隱藏的信息。控制器最好只發送絕對必要的信息來呈現頁面。

您將需要修改視圖的第一行,因爲您不再傳遞用戶列表。

@model IEnumerable<YourApp.Models.usermodel> 

@model YourApp.Models.usermodel 
相關問題